【发布时间】:2023-03-06 22:40:01
【问题描述】:
我有一个选择元素的标记:
<select type="submit" ([ngModel])="selectedValue" #item (change)="onSelectItem(item.value)">
<option>Pick an option</option>
<option *ngFor="let object of objects">{{ object.value }}</option>
</select>
当我从 typescript 更新 ngModel 绑定时,没有任何反应。本质上我只是在组件中这样做:
ngOnInit() {
this.selectedValue = 'something' // One of the options from the list of objects
}
但是,什么也没有发生。 我试图将其更新为的值在对象列表中(在 *ngFor 中)——如果这很重要的话。
【问题讨论】:
-
查看我的编辑,了解有关
[ngModel]和(ngModelChange)的更多信息。
标签: html angular html-select