问题
This is my code:
<div *ngFor="let product of products | mypipe : cb.checked : cb.value">
<label>{{product.productName}} - {{product.productColor}}</label>
</div>
<!--<div *ngFor="let color of colors">-->
<input #cb type="checkbox" [(ngModel)]="cb.checked" [value]="'Blue'" />
<label>{{color}}</label>
<!--</div>-->
It works fine with the code commented but if i uncommet it, it doesnt work. My goal is to have multiple checkboxes created dynamic and filter some data. I can do it with just one checkbox created manualy (when the code is commented) but not with multiple dynamic created checkboxs.
I hope to have explained my problem well.
By the way, this is my pipe code:
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'mypipe',
})
export class TestePipe implements PipeTransform {
transform(value: any, args1?: any,args2?: any): any {
return value.filter(product => {
if (args1) {
return product.productColor === args2;
}
return value;
});
}
}
来源:https://stackoverflow.com/questions/39521452/how-to-filter-data-with-dynamic-created-checkboxs