0

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.

1 Answer 1

2

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)
    );
Sign up to request clarification or add additional context in comments.

1 Comment

Omg, i you're right. i should've know.. New to typescript, well know with javascript. Thnx! (will accept your answer once allowed by stackoverflow)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.