Answer the question
In order to leave comments, you need to log in
Why is no content displayed when using the Promise method in Angular 4?
Hello.
I have such a problem: the contents of the array passed from the api are not displayed. It is visible in the console but does not display on the screen. Before that, I did not use the Promise method and everything worked.
service
getAllUsers(): Promise<User[]> {
return this.http.get(this.apiUrl)
.toPromise()
.then(res => res.json().data as User[])
.catch(this.handleError);
}
ngOnInit() {
this.usersService.getAllUsers().then(users => this.users = users);
}
<tr *ngFor="let user of users">
<td>{{ user._id }}</td>
<td>{{ user.first_name }}</td>
<td>{{ user.last_name }}</td>
<td>{{ user.email }}</td>
</tr>
export class User {
_id: any;
first_name: string;
last_name: string;
email: string;
}
[{"_id":1,"first_name":"Jena","last_name":"Savidge","email":"[email protected]"},{"_id":2,"first_name":"Rheta","last_name":"Dye","email":"[email protected]"}}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question