Issue
In the Angular Material documentation, they say [formControlName] cannot be used with a mat-checkbox. How can I create checkboxes dynamically according to an array of values and get checkbox value using reactive forms? Is there an alternative way?
Solution
Seems you misunderstood docs. formControlName work with mat-checkbox and you can create them dynamically:
<form [formGroup]="myForm">
<ng-container *ngFor="let field of fields">
<mat-checkbox
[formControlName]="field.name"
[labelPosition]="field.labelPosition"
[disabled]="field.disabled"
[checked]="field.checked"
>
{{field.label}}
</mat-checkbox>
</ng-container>
</form>
Answered By - V.Tur
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.