<span *ngFor="let op of [{‘id‘:‘a‘,‘text‘:‘11‘},{‘id‘:‘b‘,‘text‘:‘2222‘},{‘id‘:‘cc‘,‘text‘:‘3333‘}]" class="form-check">
<input type="checkbox" [name]="value" [checked]="model.indexOf(op.id) > -1" (click)="setValue(op)"
[value]="op.id"/>{{op.text}}{{model| json}}
</span>
setValue(option: any) {
const {id} = option;
const index = this.model.indexOf(id);
if (index > -1) {
// 有则移出
this.model.splice(index, 1);
this.onChange(this.model); // 需更新绑定的值
} else {
// 无则添加
this.model.push(id);
this.onChange(this.model); // 需更新绑定的值
}
}
<!-- <span *ngFor="let op of [{‘id‘:‘a‘,‘text‘:‘a11‘},{‘id‘:‘b‘,‘text‘:‘bbb‘}]" class="form-check">
<input type="radio" [(ngModel)]="value" name="value" [value]="op.id" />
{{value}}{{op.text}}
</span> -->