mardi 20 juin 2017

Handle change on checkbox Angular2

I have checkbox and I want use (change) on it. Default is "checked", but after click I want clear input text "Activation key". After re-checked I want generate guid and add again to input. How to get if the checkbox is selected or no?

      <div class="checkbox">
                        <label>
                         <input type="checkbox" checked (change)="handleChange($event)" > Generate key
                        </label>
                    </div>


handleChange(e) {
var isChecked = e.isChecked;
if (isChecked) {
  this.gatewayForm.patchValue({ 'activationKey': this.guid() });
}
else {
  this.gatewayForm.controls['activationKey']
    .setValue('', { onlySelf: true });
}

}




Aucun commentaire:

Enregistrer un commentaire