pipe - How to use multiple checkbox to filter data in Angular 2 -
i'm creating filter page angular 2. data being filtered depending on checkboxes checked.
this html
<input required type="checkbox" name="checkbox" value="value1" (change)="togglefilter(kind.value)" #kind/> filter option 1 <input required type="checkbox" name="checkbox" value="value2" (change)="togglefilter(kind2.value)" #kind2 /> filter option 2 <input required type="checkbox" name="checkbox" value="value3" (change)="togglefilter(kind3.value)" #kind3 /> filter option 3 <div *ngfor="let item of (items | filterpipe: filterformat)"> {{item.id}} {{item-title}} </div>
this piece of item component. in togglefilter()
i'm population array filteroptions
values of checkbox. get filterformat()
returns populated array , places argument in filterpipe
(which located in html)
filteroptions: [] = []; togglefilter(value: any) { let index = this.filteroptions.indexof(value); if (index > -1) { this.filteroptions.splice(index, 1); } else { this.filteroptions.push(value); } return this.filteroptions; } filterformat() { console.log('call filterformat'); return this.filteroptions.map(res => res); }
how can use checkboxes pipe arguments in able filter data?
Comments
Post a Comment