[英]how to disable a form element of formArray in reactive formGroup using Angular5
I am having two dropdown in an formArray. 我在formArray中有两个下拉菜单。
<select formControlName="access" (change)="checkValue($event)" >
<option[value]="1">Admin</option>
<option[value]="2">Customer</option>
</select>
<mat-select formControlName="regions" multiple>
<mat-option *ngFor="let region of regionArray" [value]="region.regionId">{{region.description}}</mat-option>
</mat-select>
I am disabling the regions selection if the access selected is as Admin. 如果所选访问权限为“管理员”,则我将禁用区域选择。
checkValue(event) {
if (event.currentTarget.value === "1") {
return this.myForm = this.fb.group({
user: this.fb.array([this.disableDetail(), ])
});
} else {
return this.myForm = this.fb.group({
user: this.fb.array([this.enableDetail(), ])
});
}
}
enableDetail() {
return this.fb.group({
regions: [{value:'',Validators: Validators.required, disabled:false}] });
}
disableDetail() {
return this.fb.group({
regions: [{value:'', disabled:true}] });
}
I am facing issue that it is affecting the other form array. 我面临的问题是它会影响其他表单数组。 I want if the dropdown value I am choosing as Admin it should disable and select all values of region dropdown only for that particular formarray.
我想要如果我选择作为管理员的下拉列表值应该禁用并选择仅针对该特定formarray的区域下拉列表的所有值。
HTML 的HTML
<select formControlName="access" (change)="checkValue($event)" >
<option[value]="1">Admin</option>
<option[value]="2">Customer</option>
</select>
<mat-select [disabled]="isAdmin" formControlName="regions" multiple>
<mat-option *ngFor="let region of regionArray" [value]="region.regionId">{{region.description}}</mat-option>
</mat-select>
Component 零件
isAdmin: boolean;
checkValue(event) {
this.isAdmin = event.currentTarget.value === "1";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.