垫选择默认值不能通过编程设置

时间:2020-09-10 04:59:06

标签: angular angular-material

我将第一个值(mat-option)硬编码为html:

<mat-option value="0">All</mat-option>

并且数据中的值为0:

this.selectedTeamCode.peopleId = 0

下面是我的html和ts:

html

 <mat-form-field appearance="standard">
        <mat-label>People</mat-label>
        <mat-select placeholder="Select me" formControlName="peopleId">
          <mat-option value="0">All</mat-option>
          <mat-option *ngFor="let people of peopleList"
                      [value]="people.id">{{people.peopleName}}</mat-option>
        </mat-select>
      </mat-form-field>

ts

constructor(private store: Store<fromCore.State>,
              fb: FormBuilder,
              @Inject(MAT_DIALOG_DATA) public data: { org: Organization[], people: People[]}) {
    this.selectedTeamCode = this.data.teamCode;
    this.peopleList = this.data.peopleList;

    this.updateTerminationCodeForm = fb.group({
      peopleId: [this.selectedTeamCode.peopleId, Validators.compose([Validators.required])],
      teamCode: [this.selectedTeamCode.teamCode, Validators.compose([Validators.required, Validators.maxLength(30)])],
      teamReason: [this.selectedTeamCode.teamReason, Validators.compose([Validators.required])],
      isActive: this.selectedTeamCode.isActive
    });

0 个答案:

没有答案