更改了值,但未触发更改事件。我想在更改ischecked时触发更改
在HTML
<input class="inputStyle" type="checkbox" [checked]="isChecked" id="actA" tabindex="0" (change)="onAct($event)">
还有其他功能(以ts为单位)
onChangeoption(lang) {
this.isChecked = true; `enter code here`
}
What you are trying to do is trigger a
change
event after you have programatically changed the value of the input first and this is not going to work.我可以建议两种方法:
Approach 1: From what you have shown in those snippets, it seems easy to call
onAct
inside theonChangeoption
. If you don't really need the change event object, you can callonAct
immediately after you change the value ofisChecked
.Approach 2: If you need the change event object, create a reference of the
input
element and programatically dispatch achange
event在您的TypeScript代码中:
并更新您的模板: