Angular Mat-select formcontrol选择默认值图形

时间:2020-07-31 09:44:44

标签: javascript angular angular10

我有一个角度为10的表格组/表格数组的表格控件,我想用mat-select和mat-option编辑ligne,但是它具有很好的价值,但是在图形上,我看不到我的值被选择。 / p>

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>

0 个答案:

没有答案
相关问题