答案 0 :(得分:1)
您可以使用CSS进行破解,但这确实很hacky。在主机包装器组件.scss中:
:host {
.mat-slide-toggle {
&.mat-checked {
::ng-deep.mat-slide-toggle-bar::after {
content: 'ON';
font-size: 45%;
font-weight: 700;
color: black;
position: absolute;
left: 4px;
top: -5px;
}
}
&:not(.mat-checked) {
::ng-deep.mat-slide-toggle-bar::after {
content: 'OFF';
font-size: 45%;
font-weight: 700;
color: white;
position: absolute;
left: 21px;
top: -5px;
}
}
}
}
答案 1 :(得分:0)
角材料组件未构建为可扩展的 检查:https://github.com/angular/components/issues/10208
相反,您可以创建自己的自定义表单字段 检查:https://material.angular.io/guide/creating-a-custom-form-field-control