A Accountpage should return Data to the logged in user. I've got following code:
http.get.service.ts
getUserData() {
const token = this.currentUser.token;
const body = JSON.stringify({token: token});
return this.http.post('https://test.com/src/getuserdata', body)
.map((response: Response) => {
const data = response.json();
const returnArray = [];
for (let key in data) {
returnArray.push(data[key]);
}
return returnArray;
});
}
The Output of the called JSON File is:
{
"email":"[email protected]","lastname":"Grimes"
}
account.component.ts
export class AccountComponent implements OnInit {
userData: any = [];
constructor(private httpService: HttpService) { }
ngOnInit() {
this.httpService.getUserData()
.subscribe(
data => {
this.userData = data;
}
);
}
}
The response of ngOnInit is "[email protected], Grimes"
account.component.html
...
<div class="n-r-m-e" [innerText]="userData.email">
<div class="n-r-m-e-v" [innerText]="userData.lastname">
...
The div-tags return "undefinded". How can i fix this problem?