簡體   English   中英

默認選擇值未出現在 angular 的下拉列表中

[英]default selected value is not comming in dropdown in angular

我想知道為什么選擇的值沒有出現在下拉值中? 下面是我的代碼:

<select [(ngModel)]="stExamSelected" (change)="StudentfilterSelected('exam',$event.target.value)" class="form-control">
   <option [ngValue]="" selected>All Exam</option>
   <option *ngFor="let exam of filteredStudentExamsList | async" [ngValue]="exam"> 
   {{exam.examName}}</option>

在這里,All Exam 默認情況下沒有選擇,誰能告訴它為什么會發生以及解決方案是什么?

[ngValue]需要一個屬性,要給它一個字符串,你需要兩個引號[ngValue]="''"

value=""也可以。

selected是不必要的,因為您將下拉列表綁定到stExamSelected 只需將此屬性初始化為空字符串,它就會 select 該選項。

stExamSelected = '';
<select [(ngModel)]="stExamSelected" (change)="StudentfilterSelected('exam',$event.target.value)" class="form-control">
   <option value="">All Exam</option>
   <option *ngFor="let exam of filteredStudentExamsList | async" [ngValue]="exam"> 
   {{exam.examName}}</option>

暫無
暫無

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

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