Issue
I've been looking for similar issues but couldn't understand what my problem is. I am a rookie with Angular.
I am calling the service.getUsers()
. And getting data successfully. But I've noticed that this.userList
is undefined
when I was debugging the code (shown on the image). My problem is I can't iterate userList
it says ERROR TypeError: this.userList is not iterable
But on HTML I am using the userList
as a resource to my table. I can see the data that I am getting from DB. So how am I seeing that data if it's undefined and not iterable? I need to use userList
for loop in the same class.
this.service.getUsers().subscribe(data => { this.userList = data; });
testFunction() {
for (let user of this.userList) {
this.selectedUserList.push(user);
}
}
Solution
Thank you everyone. I figured it out.
this.service.getUsers().subscribe(data=>{this.userList=data; console.log(data); this.testFunction();});
I called the function within the subscribe worked fine.
Answered By - Bugra Kabiman
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.