Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get input checkbox (change) event value on and off?

The result always coming as "on". I want to make it get two results when on and off.

  <label class="switch switch-3d switch-primary switch-success">
    <input type="checkbox" (change)="isChangeLimitAccessToggle($event.target.value)" id="ifLimitAccess" class="switch-input">
    <!-- [attr.disabled]="switchDisable?'':null"  [checked]="switchEnable" -->
    <span class="switch-label" data-on="Yes" data-off="No"></span>
    <span class="switch-handle"></span>
  </label>
like image 983
Chanaka Amarasinghe Avatar asked Jul 20 '18 06:07

Chanaka Amarasinghe


2 Answers

Just use checked attribute:

<input type="checkbox" (change)="isChangeLimitAccessToggle($event.target.checked ? 'on' : 'off')" id="ifLimitAccess" class="switch-input">
like image 150
Azamat Zorkanov Avatar answered Sep 30 '22 19:09

Azamat Zorkanov


Add the [(ngModel)] directive to your input:

<label class="switch switch-3d switch-primary switch-success">
<input type="checkbox" [(ngModel)]="checkboxValue"(change)="isChangeLimitAccessToggle(checkboxValue)" id="ifLimitAccess" class="switch-input">
<!-- [attr.disabled]="switchDisable?'':null"  [checked]="switchEnable" -->
<span class="switch-label" data-on="Yes" data-off="No"></span>
<span class="switch-handle"></span>

like image 34
Michael Desigaud Avatar answered Sep 30 '22 17:09

Michael Desigaud