Reputation: 33
I cannot make ES5 filter function works with Angular 2 (with TypeScript).
My filter function looks like this:
getApplicableNotes(): void {
this.noteService
.getNotes()
.then(notes => {
notes.filter((note) => !note._deleted && !note._done);
this.notes = notes;
})
.catch((error) => this.error = error);
}
My TypeScript class is extremely straightforward:
export class Note {
id: number;
title: string;
description: string;
_starred = false;
_done = false;
_deleted = false;
constructor(id: number, title: string, description: string, starred?: boolean, done?: boolean, deleted?: boolean) {
this.id = id;
this.title = title;
this.description = description;
this._starred = starred ? starred : false;
this._done = done ? done : false;
this._deleted = deleted ? deleted : false;
};
}
Although, my notes array is never filtered, no matter what properties I will set up in Note constructor.
Upvotes: 0
Views: 113
Reputation: 92521
The filter()
method doesn't modify the array, but returns a new filtered array. You should assign the result to this.notes
:
.then(notes => {
this.notes = notes.filter((note) => !note._deleted && !note._done);
})
Upvotes: 2