【发布时间】:2020-02-28 07:03:26
【问题描述】:
我正在尝试在 Angular 8 中更新 select 中的值。 我发现我可以使用:
$('#selectSeccion').val("SeccionOption");
这个选择是下一个:
<select name="seccion" class="form-control" id = "selectSeccion">
<option *ngFor="let seccion of seccion" [ngValue]="seccion">{{seccion.seccion}}</option>
</select>
当我将 select 与 Angular 一起使用时,jQuery 代码不起作用,仅当 select 是正常的 html 时才起作用,例如下一个:
<select class="form-control" id = "prueba">
<option value = ""></option>
<option value = "other">other</option>
</select>
如何更新“ng”选择的值?
【问题讨论】:
-
这能回答你的问题吗? Binding select element to object in Angular
-
不要为此使用 jquery。通读文档或跟随英雄之旅教程,以便您更好地了解 Angular 的基础知识。
-
@Igor 我不是使用 Angular 的专家,可能绑定是答案,但是,您指出的答案不是更新选择,它会根据选择的更改更新值,但选择已更新手动,谢谢
标签: javascript jquery html angular typescript