export class EmployeeDetailsComponent implements OnInit {
employees: any = [];
public errorMsg;
// you can define also below
// errorMsg:any = [];
constructor(private _employeeService: EmployeeService) {}
ngOnInit() {
this._employeeService.getEpmloyees().subscribe(
data => (this.employees = data),
error => (this.errorMsg = error)
);
}
applyFilter(filterValue: string) {
this.employees.filter = filterValue.trim().toLocaleLowerCase();
}
}
<body>
<p><input type="text" (keyup)="applyFilter($event.value)"></p>
<table border="1">
<tr>
<th>ID</th>
<th>NAME</th>
<th>AGE</th>
<th>Mobile</th>
</tr>
<tbody *ngFor="let employee of employees; i as index">
<tr>
<td>{{employee.id}}</td>
<td>{{employee.name}}</td>
<td>{{employee.age}}</td>
<td>{{employee.mob}}</td>
</tr>
</tbody>
</table>
</body>
Above is my code I just wanted to know what is going wrong in the filter method what I exactly need to change to make this work. and how do I fetch properly filtered data?