【发布时间】:2021-10-23 04:33:53
【问题描述】:
我想在材料选择中使用默认/初始值。我尝试添加 [(value)]=initialValaue ,[value]=initialValue。但它们不起作用。 我有我在表中列出的建筑物。而且每栋建筑的翼楼都很少(我把建筑分成几部分,就像在医院里你有不同的建筑部分)。我使用 select do 显示所有建筑物的翅膀,以便用户可以选择他想要的。但我希望在用户选择之前选择默认值。
<mat-form-field *ngIf="getSpecificPodZg(element.key).length" >
<mat-label>Podzgrada</mat-label>
<mat-select [(value)]="selectedPod" [(ngModel)]="is_selected[i]" disableOptionCentering class="mySelectClass">
<mat-option *ngFor="let zgrada of getSpecificPodZg(element.key)" [value]="zgrada.key" required >
{{zgrada.ime}}
</mat-option>
</mat-select>
</mat-form-field>
和我的带有函数的 ts 文件
getSpecificPodZg(zg_idd:String){
this.SpecificPodZg=[];
this.PodZgrada.forEach((element: any) => {
if(element.zg_id==zg_idd){
this.SpecificPodZg.push(element);
}
});
return this.SpecificPodZg;
也试过这个:用 [selected]
<mat-form-field *ngIf="getSpecificPodZg(element.key).length" >
<mat-label>Podzgrada</mat-label>
<mat-select [(ngModel)]="is_selected[i]" disableOptionCentering class="mySelectClass">
<mat-option *ngFor="let zgrada of getSpecificPodZg(element.key); let i = index" [value]="zgrada.key" [selected]="i===0" >
{{zgrada.ime}}
</mat-option>
</mat-select>
</mat-form-field
【问题讨论】:
标签: html angular forms select angular-material