如何在检查角度2.0中的复选框时调用函数

cod*_*de1 4 typescript angular

我目前正在使用角度2.0.在HTML中,我有一个复选框,代码如下所述.

<div style="margin-left:15px;">
            <label>Draw</label>
            <input id="isCheckBox" type="checkbox" checked="checked">
</div>
Run Code Online (Sandbox Code Playgroud)

如果在typescript文件中选中复选框,如何调用函数?

Saj*_*ran 14

你可以这样做,

<input type="checkbox"  id="isCheckBox" (change)="yourfunc($event)"/>
Run Code Online (Sandbox Code Playgroud)

在打字稿中,

yourfunc(e) {
   if(e.target.checked){        
   }
}
Run Code Online (Sandbox Code Playgroud)