8

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>

3 Answers 3

15

Just use checked attribute:

<input type="checkbox" (change)="isChangeLimitAccessToggle($event.target.checked ? 'on' : 'off')" id="ifLimitAccess" class="switch-input">
Sign up to request clarification or add additional context in comments.

3 Comments

If someone uses mat-checkbox instead of input, then use $event.checked, since there is no attribute target in that case.
won't work with strict checks.
That's true - the types are somehow not correct. Anyone know how to strictly type that?
2

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>

1 Comment

this one also if we are using formControlName
0
<input type="checkbox" value = "1"(change)="isChangeLimitAccessToggle($event.target.value)"  class="switch-input">

you can pass value in input tag and when you will click on check box then you get 1 value so it will work for you.

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.