过滤管不工作Angular 5

时间:2018-06-18 14:55:43

标签: javascript angular typescript firebase

我正在尝试通过用户输入从firebase过滤数据。我已经创建了一个管道来处理这个,但我一直收到错误:

ERROR TypeError: Cannot read property 'indexOf' of undefined

我的HTML是:

  <div class="container-fluid">
    <div class="col-md-6">
      <input class="search" type="text" placeholder="search proerties by post-code" [(ngModel)]="searchTerm">
    </div>
    <div class="row">
      <div class="col-md-4" *ngFor="let property of properties | propertyFilter:searchTerm">
        {{property.post_code}}
      </div>
    </div>
  </div>

ts文件如下:

export class SearchPropertiesComponent implements OnInit {
public properties: PropertyModel[];
routing = environment.routing;
searchTerm: string;

  constructor(private _property: PropertyManageService) {
    this._property.getAllProperties().valueChanges().subscribe(properties => {
      console.log(properties);
      this.properties = properties;
    })
   }

  ngOnInit() {
  }

}

最后是我的烟斗:

@Pipe({
  name: 'propertyFilter'
})
export class PropertyFilterPipe implements PipeTransform {

transform(properties: PropertyModel[], searchTerm: string): PropertyModel[] {
  if(!properties || !searchTerm) {
    return properties;
  }
  return properties.filter(property =>
    property.post_code.indexOf(searchTerm) !== -1); //ERROR HERE
}

}

我尝试将post_code更改为我收到的对象中的其他字段,但我仍然遇到同样的问题。我想这意味着信息实际上从来没有真正得到这个未定义的信息吗?

有什么建议吗?

0 个答案:

没有答案