簡體   English   中英

Angular 2模型驅動表單中的默認無效選擇選項?

[英]Default invalid select option in Angular 2 model-driven forms?

有沒有辦法在Angular 2模型驅動的表單中實現無效的默認選擇選項?

我在尋找這樣的東西:

<select name="DateExpiryMonth" [(ngModel)]="model.DateExpiryMonth" ngControl="dateExpiryMonth" required>
    <option value="" selected="selected" disabled>Month...</option>
    <option *ngFor="let month of months" [value]="month">{{ month }}</option>
</select>

理想情況下,select上的required屬性將確保Angular 2將第一個<option>視為無效,但我找不到任何表明這是可行的文檔。

目前,第一個“月......”選項被Angular 2視為有效。

我不認為這是一個理想的解決方案,但我發現如果我將模型中的字段設置為null或undefined(在您的情況下為model.dateExpiryMonth ),則angular會認為表單無效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM