Reputation: 9029
I am currently using angular 2.0. In HTML, I have a checkbox, the code is as mentioned below.
<div style="margin-left:15px;">
<label>Draw</label>
<input id="isCheckBox" type="checkbox" checked="checked">
</div>
How to call a function only if a checkbox is checked in typescript file?
Upvotes: 10
Views: 33154
Reputation: 891
You can use currentTarget if target won't work,
<input type="checkbox" id="isCheckBox" (change)="yourfunc($event)"/>
and in typescript,
yourfunc(e) {
if(e.currentTarget.checked){
}
}
Upvotes: 1
Reputation: 222722
You can do this,
<input type="checkbox" id="isCheckBox" (change)="yourfunc($event)"/>
and in typescript,
yourfunc(e) {
if(e.target.checked){
}
}
Upvotes: 31