angular - How to read Angular2 json map object in angular2 -
i trying fetch json object in angular 2 has key value pair.
your question not clear. demonstrate things understood question.
here's sample code (assuming value pair username & password)
let params:urlsearchparams = new urlsearchparams(); params.set('username', username); params.set("password", password); return this.http.post(this.baseurl + '/auth/credential', '', {search: params}).map((res:response) => res.json());
i defined above method getuserdetails() global service , import dataservice particular component mentioned below,assuming server send reply inside array called results(cant out looking @ back-end implementation of project)
this.dataservice.getuserdetails().subscribe( (data) => { console.log('fetched userdata edit', data.results) this.modify_users = data.results; console.log(data.results); console.log(this.modify_users); }, (error) => { console.log('failure viewuserdetails'); alert('error getting user details edit'); });
so if describe on i'm doing here is,
(data) =>{}: define next when receive kind of data server.
(error)=>{}: define next when server replied withan error
Comments
Post a Comment