2016-10-11 26 views
1

我有一个选择组件是这样的:angular2选择禁用第一要素

<select name="typeSelection" materialize="material_select" 
     [(ngModel)]="trainingplan.type" > 
    <option [ngValue] = "null" disabled selected>Please choose a type</option> 
    <option [ngValue]="type" *ngFor="let type of firebaseService.trainingTypes"> 
    {{type.name}} 
    </option> 
</select> 

我想第一个选项被禁用,因此用户可以看到这个提示。但是取而代之的是,“训练类型”的第一个条目被选中。我想这是因为Angular可能不知道要选择哪一个,因此它需要第一个。我能做些什么呢?

回答

0

您的trainingplan.type需要设置为null但据我所知[ngValue]与空将只在下一次更新后工作。

您需要为第一个选项选择不同的值,并将trainingplan.type设置为该值。您可以删除selected属性。

相关问题