Can't read the 'null property filter in angular 2?

I get this error. Cannot read 'null property filter

when i apply the filter in angular 2. Here is my code

http://plnkr.co/edit/K46jJsnmHiONuqIsnuzW?p=preview

import {Pipe} from 'angular2/core';

@Pipe({
  name: 'sortByName',
  pure: false,
})
export class SortByNamePipe {

  transform (value, [queryString]) {
    // console.log(value, queryString);
    return value.filter((student)=>new RegExp(queryString).test(student.name))
    // return value;
  }
}
+4
source share
1 answer

This is because you have data as input, which is loaded asynchronously using an HTTP request.

You need to check this before using the filter:

export class SortByNamePipe {
  transform (value, [queryString]) {
    if (value==null) {
      return null;
    }

    return value.filter((student)=>new RegExp(queryString).test(student.name))
    // return value;
  }
}
+11
source

Source: https://habr.com/ru/post/1628287/


All Articles