How to filter data with dynamic created checkboxs?

守給你的承諾、 提交于 2020-01-04 02:16:47

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!