我将第一个值(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
});