how to make text on the mat-slide-toggle

882 Views Asked by At

how to put text on mat-slide-toggle like when it is true I want to show it as assigned and when false not assigned

<mat-slide-toggle (click)="openDialog1(element.courseId, true )" [checked]="checked">Assign All</mat-slide-toggle> 
1

There are 1 best solutions below

2
On

Remove [checked]="checked" and use [(ngModel)] instead, and show html content based on the flag, like this -

<mat-slide-toggle (click)="openDialog1(element.courseId, true )" [(ngModel)]="checked">{{ checked ? 'assigned' : 'not assigned' }}</mat-slide-toggle>

Declare a flag in ts file -

checked: boolean;