如果切换选中 ionic 3 angular 2+,则取消禁用提交按钮

Un-Disable submit button if toggles checked ionic 3 angular 2+

我正在处理的一个表单包含两个切换按钮,选中后将允许用户提交表单。但是,虽然我能够禁用该按钮,并且如果选中任一切换按钮,则当前逻辑会启用该按钮,但我无法仅在选中两个切换按钮时启用该按钮。

  <ion-item>
    <ion-label style="font-size:14px">I am over 13 years of age</ion-label>
    <ion-toggle [(ngModel)]="age" checked="false" [ngModelOptions]="{standalone: true}"></ion-toggle>
  </ion-item>

  <ion-item >
    <ion-label style="font-size:14px" class="line-break">I agree to the <a (click)="openModal('privacy')">Privacy Policy</a> & <a (click)="openModal('terms')">Terms</a></ion-label>
    <ion-toggle [(ngModel)]="termsprivacy" checked="false" [ngModelOptions]="{standalone: true}"></ion-toggle>
  </ion-item>

  <button [(disabled)]="termsprivacy && age" ion-button block type="submit">
    Create an Account
  </button>

处理您的提交后,您需要设置这些变量,否则一旦您设置了它们,它们将始终设置为 true 并且按钮将始终被禁用。

termsprivacy == false && age == false

好的,这有效,注意 [(disabled)]="!termsprivacy || !age":

  <ion-item>
    <ion-label style="font-size:14px">I am over 13 years of age</ion-label>
    <ion-toggle [(ngModel)]="age" checked="false" [ngModelOptions]="{standalone: true}"></ion-toggle>
  </ion-item>

  <ion-item >
    <ion-label style="font-size:14px" class="line-break">I agree to the <a (click)="openModal('privacy')">Privacy Policy</a> & <a (click)="openModal('terms')">Terms</a></ion-label>
    <ion-toggle [(ngModel)]="termsprivacy" checked="false" [ngModelOptions]="{standalone: true}"></ion-toggle>
  </ion-item>

  <button [(disabled)]="!termsprivacy || !age" ion-button block type="submit">
    Create an Account
  </button>