我在页面上有一个角度组件,它绑定了所有选项。
使用jQuery,我能够用以下内容检索正确的选定值:
$('#mat-select').val(); // returns me the id of the selected option
然而,当我尝试使用jQuery更新值时,该值会被更新,但不会反映在屏幕上的组件上。
例如。
$('#mat-select').val(); // eg. returns 'mat-select-option-0'
$('#mat-select').val('mat-select-option-5').trigger('input').trigger('change');
$('#mat-select').val(); // returns me 'mat-select-option-5'
然而,组件上的选定值看起来仍然是mat-select-option-0
。我猜我只是在设置dom的value
属性,而不是更新角度组件,但不知道如何更新。
有人能提供建议吗?
不建议将jQuery与Angular一起使用,因为它们通常以自己的方式使用domhttps://ng-bootstrap.github.io/#/getting-启动
这将使你避免未来的许多问题。