I've created a UsersComponent which calls a UserService that returns a
collection of users:
getUsers(): void {
this.userService
.getUsers()
//.then(this.extractData)
.then(users => this.users = users)
.then(console.log(this.users))
}
When my UsersComponent runs the code above, "undefined" is written to the
console. However, if I uncomment the extractData reference above then the
response parameter in the function below has the user objects as expected:
extractData(response: Response) {
this.users = response;}
However in the runtime context of the function above, "this" is null so the
code errors out. UsersComponent has a users variable of type User[] like
this:
users: User[];
So what do I need to to in order to set the collection of user objects
returned from the UserService to the users member variable of the
UsersComponent?
--
You received this message because you are subscribed to the Google Groups
"Angular" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.