这里我写了一个简单的搜索功能,它通过一个错误,因为it.toLowerCase()。includes(searchText);
搜索代码
@Pipe({
name: 'filter'
})
export class FilterPipe implements PipeTransform {
debuger;
transform(items: any[], searchText: string): any[] {
if(!items) return [];
if(!searchText) return items;
searchText = searchText.toLowerCase();
return items.filter( it => {
return it.toLowerCase().includes(searchText);
});
}
}
表格
<input [(ngModel)]="searchText" placeholder="enter search term here">
<table class="table table-sm">
<thead>
<tr>
<th>Auction ID</th>
<th>Auction Name</th>
</thead>
<tbody>
<tr *ngFor="let value of auction?.data | filter :searchText">
<tr>
<th>Auction ID</th>
<th>Auction Name</th>
<tr/>