Javascript 带TS的角度2 ES6滤波器

Javascript 带TS的角度2 ES6滤波器,javascript,angular,typescript,Javascript,Angular,Typescript,我无法使ES6过滤器功能与Angular 2(带TypeScript)一起工作 我的筛选函数如下所示: getApplicableNotes(): void { this.noteService .getNotes() .then(notes => { notes.filter((note) => !note._deleted && !note._done); this.notes = notes; }) .catch((error)

我无法使ES6过滤器功能与Angular 2(带TypeScript)一起工作

我的筛选函数如下所示:

getApplicableNotes(): void {
this.noteService
  .getNotes()
  .then(notes => {
    notes.filter((note) => !note._deleted && !note._done);
    this.notes = notes;
  })
  .catch((error) => this.error = error);
}
我的TypeScript类非常简单:

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;
  };

}
尽管如此,我的notes数组从未被过滤,无论我将在notes构造函数中设置什么属性。

该方法不会修改数组,而是返回一个新的过滤数组。您应该将结果分配给此。注意:

.then(notes => {
  this.notes = notes.filter((note) => !note._deleted && !note._done);
})
该方法不修改数组,但返回一个新的筛选数组。您应该将结果分配给此。注意:

.then(notes => {
  this.notes = notes.filter((note) => !note._deleted && !note._done);
})