Angular 下拉不显示元素
Angular Drop Down Not Showing Elements
在我的 html 组件中,我有以下内容:
<select class="hideLabel form-control" [(ngModel)]="model.powerPlantType" name="powerPlantType" (change)="selectName();">
<option selected="" value=""></option>
<option [ngValue]="powerPlantType" *ngFor="let powerPlantType of powerPlantTypes">
{{ powerPlantType }}
</option>
</select>
显示正常,如下图所示:
如何在页面加载时添加一条消息“--Select 输入--”?
编辑:根据下面post的建议,我仍然无法让它工作:所以当页面加载时,下拉列表仍然是空的,没有预期的默认测试“--Select 输入--
但是选择下拉菜单时似乎出现了测试!
我希望页面加载时是这样的:
将您的 html 更改为以下内容:
<select class="hideLabel form-control" [(ngModel)]="model.powerPlantType" name="powerPlantType" (change)="selectName();">
<option selected="" value="">--Select Type--</option>
<option [ngValue]="powerPlantType" *ngFor="let powerPlantType of powerPlantTypes">
{{ powerPlantType }}
</option>
</select>
在我的 html 组件中,我有以下内容:
<select class="hideLabel form-control" [(ngModel)]="model.powerPlantType" name="powerPlantType" (change)="selectName();">
<option selected="" value=""></option>
<option [ngValue]="powerPlantType" *ngFor="let powerPlantType of powerPlantTypes">
{{ powerPlantType }}
</option>
</select>
显示正常,如下图所示:
如何在页面加载时添加一条消息“--Select 输入--”?
编辑:根据下面post的建议,我仍然无法让它工作:所以当页面加载时,下拉列表仍然是空的,没有预期的默认测试“--Select 输入--
但是选择下拉菜单时似乎出现了测试!
我希望页面加载时是这样的:
将您的 html 更改为以下内容:
<select class="hideLabel form-control" [(ngModel)]="model.powerPlantType" name="powerPlantType" (change)="selectName();">
<option selected="" value="">--Select Type--</option>
<option [ngValue]="powerPlantType" *ngFor="let powerPlantType of powerPlantTypes">
{{ powerPlantType }}
</option>
</select>