Вы можете попробовать это решение
HTML-файл (например, app.component.html)
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox"
id="myonoffswitch" [checked]="isSwitched"
(change)="getSwitcherValue(isSwitched)">
<label class="onoffswitch-label" for="myonoffswitch">
<span #onoffswitch class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
Файл Ts (app.component.ts)
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
isSwitched:boolean=true;
getSwitcherValue(onoffswitch) {
this.isSwitched=!this.isSwitched;
console.log("onoffswitch:"+this.isSwitched);
}
}
Файл Css (app.component.css)
.onoffswitch-inner:before {
content: "ON";
padding-left: 10px;
background-color: #93297E; color: #FFFFFF;
}
.onoffswitch-inner:after {
content: "OFF";
padding-right: 10px;
background-color: #EEEEEE; color: #999999;
text-align: right;
}
Вот ссылка Демо для справки