Search code examples
javascriptangulartypescripttoggleform-control

Forcing a mat-slide-toggle to be true with formControl


Is there a way to force the mat-slide-toggle to be true under a condition. (If someone tries to make it false, either it doesnt budge, or it goes back to true instantly). Something functionally equivalent to forcedTrue="someCondtion" in

<mat-slide-toggle
    formControlName="compression"
    class="margin-top"
    forcedTrue="someCondtion">
    {{'compression' | translate}}
</mat-slide-toggle>

Solution

  • Use [checked]="true" [disabled]="true"

       <mat-slide-toggle
        formControlName="compression"
        class="margin-top"
        [checked]="true"
        [disabled]="true">
        {{'compression' | translate}}
      </mat-slide-toggle>