我正在使用带有表单生成器的 angular4 反应式表单
在我的视图组件中,我有一堆复选框,所以我创建了表单数组,加载页面后,一些复选框被选中,一些未被选中,这取决于支持的 api 数据
this.roleForm = this.fb.group({
permission: this.fb.array([])
});
this.permissionArray = <FormArray>this.roleForm.controls['permission'];
this.permissionArray.push(this.fb.group({
id: [this.newArray[p].group[k].permission.id],
key: [this.newArray[p].group[k].permission.key],
legend: [this.newArray[p].legend],
ischecked: [this.newArray[p].group[k].permission.ischecked]
})
this.newArray[p].group[k].permission.ischecked is responce from bakend(there is no issues to get)
HTml
<form name='roleForm' [formGroup]="roleForm">
<div formArrayName="permission">
<ul>
<li *ngFor="let permission of roleForm.controls.permission.controls;let i=index" [formGroupName]="i">
<input type="checkbox" [formControlName]="'ischecked'"
[checked]="permission.value.ischecked"/>
</li>
</div>
</form>
我正在检查和未检查的复选框完美无问题,我的问题是无法禁用复选框
如果我尝试如下所示,禁用工作但 [checked] 指令不起作用
this.permissionArray.push(this.fb.group({
id: [this.newArray[p].group[k].permission.id],
key: [this.newArray[p].group[k].permission.key],
legend: [this.newArray[p].legend],
ischecked: [{value:this.newArray[p].group[k].permission.ischecked, disabled: true}],
})
请帮助我,在此先感谢