[{"userID": "3","userName": "anna", "password": "pass3" }] any help you can provide would be greatly appreciated.
@Component({ selector: 'get-userlist', template: `<h2>Testing</h2> <pre>{{ this.userListReceived | json }} </pre>`, providers: [ GetUserListService ]})
export class GetUserListComponent implements OnInit { private userListReceived: UserType[]; private errMsg1: string; constructor(private getUserList: GetUserListService) {}
getUserListButtonMethod(){ this.getUserList.getUserListMethod() .subscribe( userData => this.userListReceived = userData, error => this.errMsg1 = <any>error, ()=>console.log('finished') ); }
ngOnInit(){ this.getUserListButtonMethod(); }}@Injectable()
export class GetUserListService{ private userUrl = 'http://testing.dev/angular/app/services/getUserList.php'; private getList: UserType[];
constructor( private _http: Http){}
getUserListMethod(): Observable<UserType[]>{ let headers = new Headers({ 'Content-Type': 'application/json' }); let options = new RequestOptions({ headers: headers });
var findU = JSON.stringify({userName: 'anna'}); // problem area. assuming findU isn't passed through
return this._http .post(this.userUrl, findU , options) //problem area .map((res: Response) => res.json()) .catch (error => <any>error); } //END - getUserListMethod} //END of class<?php require_once('dbtesting.php'); $dbcon = Connection::getConnection(); $findUser = $_POST['userName'] ; //problem area, assuming $findUser isn't receiving the value in this case userName for search Try{ $STMT = $dbcon ->prepare("SELECT * FROM tbl_angular WHERE userName = '$findUser' "); $STMT->execute(); $getUserlist = $STMT->fetchAll(PDO::FETCH_ASSOC); } catch(PDOException $e){ echo 'Unable to find user: ' . $e->getMessage(); } echo json_encode($getUserlist); ?>