使用Angular2更改选择选项

使用Angular2更改选择选项,angular,Angular,我想用Angular2在html的select-option中选择一个选项,但我需要为代码这样做 <select name="lastDataVi" [(ngModel)]="lastDataVi"> <option [ngValue]="undefined" selected="true" disabled="disabled">Select option</option> <option [ngValue]="vicombo.id" *n

我想用Angular2在html的select-option中选择一个选项,但我需要为代码这样做

<select name="lastDataVi" [(ngModel)]="lastDataVi">
   <option [ngValue]="undefined" selected="true" disabled="disabled">Select option</option>
   <option [ngValue]="vicombo.id" *ngFor="let vicombo of paramsServer.vicombo"> {{ vicombo.id}} </option>
   </select>

选择选项
{{vicombo.id}
虽然我有我的
选择选项

我需要在单击按钮时,将选择选项置于第一个选项->

选择您可以使用的选项

<option selected="true" disabled="true"></option>


您不需要使用ngValue

您需要使用[value]而不是[ngValue]

 <option  *ngFor="let vicombo of paramsServer.vicombo" [value]="vicombo.id"> {{ vicombo.id}} </option>
{{vicombo.id}

您只需将所选值分配给此
lastDataVi
,但在我的html中,我希望我的用户看到第一个选项,而不是我有值=未定义“仍然您的预期输出不清楚。没有ngValue。在html中,从不显示1º选项,因此您可以引用此创建的plunker。查看是否有帮助