我有一个html
码,其中我迭代数组:定制验证器来在ngFor回路中产生复选框
<div class="container">
<ol *ngFor="let g of guides">
<button type="button" class="form-control" (click)="open(g)" [class.not-confirmed]="!g.confirm" [class.confirmed]="g.confirm">{{g.description}}</button>
<div [hidden]="!g.canOpen" style="text-align: center">
<p>test</p>
<label>Zapoznałem się</label>
<input type="checkbox" [(ngModel)]="g.confirm">
</div>
</ol>
<button class="btn btn-default form-control" (click)="save()">Save</button>
</div>
是可能写一个定制的验证,以检查所有的复选框是否被选中(选中)和然后让最后一个按钮“保存”可用来点击?我开始写一些代码作为reactive forms
,但对我来说很难: 1.如何处理将根据数组大小生成的多个复选框? 2.如何添加到每个复选框的值为ngModel
这将来自后端标题为g.confirm
?
form = new FormGroup({
confirmation: new FormControl()
}, CustomValidator.checkAllCheckboxes);