2 回答

TA貢獻(xiàn)1795條經(jīng)驗(yàn) 獲得超7個(gè)贊
該option標(biāo)簽不支持該click事件。您可以改為使用標(biāo)簽change上的事件select。您還將一個(gè)對(duì)象分配給標(biāo)簽value中的屬性option,這是不正確的。要將對(duì)象分配為值,您需要使用ngValue,如果沒有為您分配唯一的 id value,例如。[value]="category.id"。
試試這個(gè)吧。
<select (change)="onCategorySelected($event.target.value)"> <!-- If you are using ngModel or formControl, get the value from there instead of using $event.target.value -->
<option *ngFor="let category of categories" [ngValue]="category">
{{category.name}}
</option>
</select>

TA貢獻(xiàn)1155條經(jīng)驗(yàn) 獲得超0個(gè)贊
使用這種方式
<select (change)="selectionChanged($event.target.value)">
....
</select>
$event.target.value將發(fā)送您更改的選項(xiàng)的值
- 2 回答
- 0 關(guān)注
- 144 瀏覽
添加回答
舉報(bào)