Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度2:输入文本更改时的文本过滤器_Angular_Angular2 Pipe - Fatal编程技术网

Angular 角度2:输入文本更改时的文本过滤器

Angular 角度2:输入文本更改时的文本过滤器,angular,angular2-pipe,Angular,Angular2 Pipe,Angular2,在我的组件.ts中,我抓取一个视频对象列表并存储在\u videos:Video[] 在我的html中,我显示视频 <tr *ngFor="#video of _videos"> 在ts中 private _videoTitleFilter: string =''; 在html中 <tr> <th><input id="videoTitleFilter" placeholder="Filter">{{_videoT

Angular2,在我的
组件.ts
中,我抓取一个视频对象列表并存储在
\u videos:Video[]

在我的html中,我显示视频

<tr *ngFor="#video of _videos">
ts

private _videoTitleFilter: string ='';
html

  <tr>
    <th><input id="videoTitleFilter" placeholder="Filter">{{_videoTitleFilter}}</th>
    <th></th>
    <th></th>
    <th></th>
  </tr>
  <tr *ngFor="#video of _videos |textfilter:'title':_videoTitleFilter">

{{{U videoTitleFilter}}

看来装订不好。这条管道第一次起作用。这里用水管对吗?或者我应该创建一个新数组
\u videoList:Video[]
,用throttle收听keyup事件以更改
\u videoList
,并在
*ngFor
中使用它,而不是
\u videos

你可以让你的烟斗不纯净:

@Pipe({
  name: 'textfilter',
  pure: false
})
export class TextFilterPipe implements PipeTransform {
  transform(items: any[], args: any[]): any {
    if(args[1].toString().length === 0)
      return items;
    return items.filter(item => item[args[0]].indexOf(args[1]) !== -1);
  }
}
这个问题可以帮助你:


您可以使您的管道不纯净:

@Pipe({
  name: 'textfilter',
  pure: false
})
export class TextFilterPipe implements PipeTransform {
  transform(items: any[], args: any[]): any {
    if(args[1].toString().length === 0)
      return items;
    return items.filter(item => item[args[0]].indexOf(args[1]) !== -1);
  }
}
这个问题可以帮助你:


Tks Thierry,已更改,仍然没有更新。我将通读这篇文章。请注意,我的视频没有更新。http获取后它保持不变。如何将您的输入绑定到
\u videoTitleFilter
属性?我的错,我更改为ngModel。TksTks Thierry,已更改,仍然没有更新。我将通读这篇文章。请注意,我的视频没有更新。http获取后它保持不变。如何将您的输入绑定到
\u videoTitleFilter
属性?我的错,我更改为ngModel。Tks