чекбоксов в масив?
export namespace ProductProperties {
export enum TestModuleOptions {
Val1 = 'Val1',
Val2 = 'Val2',
Val3 = 'Val3',
}
}
interface AddProductFormModel {
testModuleOptions: ProductProperties.TestModuleOptions[];
}
@Component({
selector: 'test-product',
templateUrl: './test.component.html',
})
export class AddProductComponent implements OnInit {
productForm = this.createForm();
productProperties = ProductProperties;
constructor(
private fb: FormBuilder,
) { }
submitCreationRequest() {
console.log(this.productForm);
}
ngOnInit(): void {
this.createForm();
this.onChanges();
}
private createForm() {
const form: FormModel<AddProductFormModel> = {
testModuleOptions: [[ProductProperties.TestModuleOptions[0]], Validators.required]
};
return this.fb.group(form);
}
private onChanges(): void {
this.productForm.valueChanges.subscribe((val) => console.log(val));
}
}
<mat-card-content>
<form [formGroup]="productForm">
<div *ngFor="let option of productProperties.TestModuleOptions | keyvalue">
<mat-checkbox
class="example-horizontal-margin"
formControlName="testModuleOptions"
[value]="option.value">
{{option.value}}
</mat-checkbox>
</div>
</form>
</mat-card-content
https://material.angular.io/components/table/overview#selection
Обсуждают сегодня