4

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>

TS

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

1 Answer 1

5

you can get checkbox status by e.target.checked

handleChange(e) {
  var isChecked = e.target.checked;
  ...
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.