I am getting a RESTful API, and I have some question about the getting JSON, here is the JSON I get:
{
“result”: “success”,
“user”: {
“loggedIn”: true,
“name”: “Nulra”,
“password”: “”
}
}
And the part for getting the JSON in auth-service.ts:
login(credentials) {
if(this.data){
return Promise.resolve(this.data);
}
let opt: RequestOptions;
let myHeaders: Headers = new Headers;
myHeaders.set('Accept', 'application/json; charset=utf-8');
myHeaders.append('Content-type', 'application/json; charset=utf-8');
opt = new RequestOptions({
headers: myHeaders
})
return new Promise(resolve => {
this.http.get(apiUrl+'login/0/login?email='+credentials.email+'&password='+credentials.password, opt)
.map(res => res.json())
.subscribe(data => {
this.data = data;
resolve(this.data);
});
});
And in my login.ts:
doLogin() {
this.authService.login(this.loginData).then(data => {
console.log("NULRA CHECKING: ",data);
}, (err) => {
});
}
I discover it just getting the user part in JSON, and missing the result part in JSON when I inspect in the console log. How can I get the both result and user part?
the console log:
Object {loggedIn: true, name: “Nulra”, password: “”}
Anybody have idea, hope for a help, Thanks a lot!!