I have a form Control in angular 10 form Group/ Form Array, i want edit the ligne with mat-select and mat-option, but its has the good value but graphically, i don't see my value selected.
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>