角度过滤器

时间:2019-08-22 18:01:38

标签: angular

我希望澄清一下,因此根据Angular文档“附录:无FilterPipe或OrderByPipe”下的说法,“ Angular不提供用于过滤或排序列表的管道。熟悉AngularJS的开发人员将其称为filter和orderBy。 Angular中没有等效项。”。

请参考文档:angular docs

因此,如果我有一个包含数据的表,并且想在表中进行搜索,那么哪种方法才是明智的选择?

我正在尝试类似的事情,

import { Pipe, PipeTransform } from '@angular/core';
import { fstorageitem } from './nemails.component';

/* in TS component */
@Pipe({ name: 'filter' })
export class Filter implements PipeTransform {
  transform(allItems: fstorageitem[]) {
  }
} 

/* in TS component */
fitem: fstorageitem;
fitems: fstorageitem[] = [];
const ncpsrole = "put whatever list of job titles" 
const fname = "put whatever list of first names" 
const lname = "put whatever list of last names" 
const email = "put whatever list of job emails" 
this.fitem = { role, fname, lname, email };
this.fitems.push(this.fitem);

export interface fstorageitem {
    role: string;
    fname: string;
    lname: string;
    email: string;
}

/* in HTML */
<tr *ngFor="let f of fitems | filter">
 <td>{{f.ncpsrole}}</td>
 <td>{{f.fname}}</td>
 <td>{{f.lname}}</td>
 <td>{{f.email}}</td>
</tr>

0 个答案:

没有答案