I am able to implement the filter on input field with the pipe. But I am not able to do so with checkbox filter.
Below is my code for input filter.
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'filter'
})
export class FilterPipe implements PipeTransform {
transform(users: any, searchTerm: any): any {
// check if search term is undefined
if (searchTerm === undefined) {
return users;
}
// return updated users array
return users.filter(function(user) {
return user.name.toLowerCase().includes(searchTerm.toLowerCase());
});
}
}
UserComponent.html
<input type="text" [(ngModel)]="searchTerm">
<table>
<tr *ngFor="let user of users | filter: searchTerm">
<td>{{user.name}}</td>
<td>{{user.type}}</td>
</tr>
</table>
Now for type
I want to filter on checkbox select.
<tr>
<td *ngFor="let role of roles">
<label>{{role.type}}</label>
<input type="checkbox">
</td>
</tr>
In input field i can get the value using [(ngModel)]
but in checkbox, I am not able to do so.
Please let me know how could I achieve using checkbox select.
Thank you