Reputation: 862
In my view i'm rendering a list of skills, using an observable and *ngFor
I retrieve the skills with the following code:
getSkills(): void {
this.skillsDataService.getSkills()
.subscribe(
skills => this.skills = skills.sort( this.skillSort )
);
}
However i've learned that it's better to use named functions and not too much nesting. So i changed the code to this:
getSkills(): void {
this.skillsDataService.getSkills()
.subscribe(
this.processSkills
);
}
processSkills(skills: Skill[]): void {
this.skills = skills.sort( this.skillSort );
}
And now the view doesn't update, eventhough this.skills is filled.
Upvotes: 0
Views: 1634
Reputation: 2771
Your "this" in processSkills will not be the controller when you call it like that. In order to understand what i mean you should just log out "this" inside of processSkills and take a course on how "this" works in JavaScript. In order to make your code work, try this instead:
.subscribe(
this.processSkills.bind(this)
);
Upvotes: 2