在反应式中,我有两个mat-slide-toggle(用一个变量绑定)。但是它们不能一起切换,当我使用[(ngModel)]时,一切都在工作。不幸的是,这个解决方案不适合我,因为mat-slide-toggle是大表格的一部分。
https:/stackblitz.comeditangular-mvpfu5-xptpb7?file=app%2Fslide-toggle-overview-example.html。
试试这个。
<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 }}