Changing handle on Angular2 checkbox
I have a checkbox and I want to use (change)
on it. The default is "checked", but after clicking I want a clean text input "Activation Key". After re-checking, I want to create a guid and add to the input again. How to get if a checkbox is checked or not?
<div class="checkbox">
<label>
<input type="checkbox" checked (change)="handleChange($event)" >
Generate key
</label>
</div>
TS
handleChange(e) {
var isChecked = e.isChecked;
if (isChecked) {
this.gatewayForm.patchValue({ 'activationKey': this.guid() });
}
else {
this.gatewayForm.controls['activationKey']
.setValue('', { onlySelf: true });
}
}
+3
source to share