angular - 带有 mat-checkbox 的 Angular 复选框列表
问题描述
我有一个带有列表形式的复选框的表单。当我选中一个复选框时,我的表单组中的值会更新,但在 HMI 级别,复选框不会保持选中状态
ngOnInit(){
const validators = [];
if(this._isRequired){
validators.push(Validators.required);
}
this.controlFormGroup.addControl(this.controlName, new FormArray([]));
this.addCheckboxes();
this.onComponentReady.emit(this.controlFormGroup);
}
get optionsFormArray() {
console.log(this.controlFormGroup.controls[this.controlName]);
return this.controlFormGroup.controls[this.controlName] as FormArray;
}
private addCheckboxes() {
this.options.forEach(() => this.optionsFormArray.push(new FormControl(false)));
}
<div [formGroup]="controlFormGroup">
<div [formArrayName]="controlName" *ngFor="let option of optionsFormArray.controls; let i = index" [ngClass]="orientation">
<mat-checkbox [formControlName]="i">
{{options[i].label}}
</mat-checkbox>
</div>
<mat-error *ngIf="controlFormGroup.controls[controlName].touched && controlFormGroup.controls[controlName].hasError('required')">
<span [innerHTML]="errorMessage"></span>
</mat-error>
</div>
我不明白问题
解决方案
推荐阅读
- flutter - SingleChildScrollView 内的颤振列不滚动
- python - 如何在 openCV 视频中放置标准过滤器?
- php - 如何从另一个 .php 文件调用 .php 文件
- python - Python Reddit API 将 gifv 转换为可读的 mp4
- java - 使用 activityForResult 后用户数据未插入到 recyclerView
- php - 子数组中带有“max”字段的 MongoDB 聚合“组”
- mysql - 是否可以在存储过程中创建具有可选数据类型的新列?
- python - 获取 Firebase 查询状态 Pyrebase
- tensorflow.js - 是否可以使用多个权重文件加载 tensorflow js 模型?
- pine-script - 通过脚本而不是通过添加指标功能将 EMA 放入 RSI 指标?