Вы должны создать фильтр
import { Injectable, Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'searchfilter'
})
@Injectable()
export class SearchFilterPipe implements PipeTransform {
transform(items: any[], searchInTable: any): any[] {
if (searchInTable === undefined) {
return null;
}
return items.filter(function(x) {
var add = x.firstname.toLowerCase().includes(searchInTable.toLowerCase());
return (add);
});
}
}
в HTML
serach: <input type="text" [(ngModel)]="searchInTable">
<table>
<thead>
<tr>
<th>first Name</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of data | searchfilter:searchInTable; let i = index">
<td>{{item.firstname}}</td>
</tr>
</tbody>
</table>
в app.module
import { SearchFilterPipe } from '../shared/filters';
declarations: [HomeComponent, SearchFilterPipe],