两个垫子-滑动-切换与反应式表格。

问题描述 投票:0回答:1

在反应式中,我有两个mat-slide-toggle(用一个变量绑定)。但是它们不能一起切换,当我使用[(ngModel)]时,一切都在工作。不幸的是,这个解决方案不适合我,因为mat-slide-toggle是大表格的一部分。

https:/stackblitz.comeditangular-mvpfu5-xptpb7?file=app%2Fslide-toggle-overview-example.html。

angular angular-material angular-reactive-forms
1个回答
1
投票

试试这个。

 <div id="pdf-content">
      <mat-slide-toggle [(ngModel)]="ifPrint"></mat-slide-toggle> {{ifPrint}}


    <mat-slide-toggle [(ngModel)]="ifPrint"></mat-slide-toggle> {{ifPrint}}
    <ul [formGroup]="form">
      <li>
                  <mat-slide-toggle [checked]="form.value.activ" formControlName="activ"  color="primary" name="active" id="active">Activ</mat-slide-toggle> 
      </li>
      <li>
              <mat-slide-toggle [checked]="form.value.activ" formControlName="activ" color="primary" name="active" id="active">Activ</mat-slide-toggle> 
      </li>
    </ul>
    {{ form?.value | json }}
© www.soinside.com 2019 - 2024. All rights reserved.