2016-10-11 63 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屬性。

相關問題