我有一个 Angular 10 表单组/表单数组的表单控件,我想使用 mat-select 和 mat-option 编辑 ligne,但它具有良好的价值,但从图形上看,我没有看到我的值被选中。
public onRowEditInit(user,index) {
console.log(this.getUsersFormGroup(index).controls['role'].value);
///{id:2, name:admin}
this.getUsersFormGroup(index).controls['role'].setValue(user.role);
this.clonedUser[user.id] = {...user};
}
createUser(p): FormGroup {
return this.formBuilder.group({
email: [p.email, [Validators.required,Validators.pattern("^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,6}$"),
Validators.maxLength(50)]],
password: ['', Validators.maxLength(20)],
role: [p.role, Validators.required],
});
}
<mat-form-field class="col-md-12 col-sm-12">
<mat-label>Role</mat-label>
<mat-select placeholder="Role" formControlName="role" [(value)]="rowData.role">
<mat-option *ngFor="let r of cbxRole" [value]="r">{{r.name}}</mat-option>
</mat-select>
</mat-form-field>
<div *ngIf="getUsersFormGroup(ri).controls['role'].errors" class="invalid-feedback">
<div *ngIf="getUsersFormGroup(ri).controls['role'].errors.required">Role obliqgatoire</div>
</div>