如何打开和关闭输入复选框(更改)事件值?

时间:2018-07-20 06:59:32

标签: angular typescript

结果始终为“ on”。我想使它在打开和关闭时都得到两个结果。

  <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 个答案:

答案 0 :(得分:2)

只需使用已选中属性:

<input type="checkbox" (change)="isChangeLimitAccessToggle($event.target.checked ? 'on' : 'off')" id="ifLimitAccess" class="switch-input">

答案 1 :(得分:1)

将[(ngModel)]指令添加到您的输入中:

<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>

答案 2 :(得分:0)

<input type="checkbox" value = "1"(change)="isChangeLimitAccessToggle($event.target.value)"  class="switch-input">

您可以在输入标签中传递值,当您单击复选框时,您将获得1个值,因此它将为您工作。