[英]How to disable angular input field by using mat-slide-toggle?
您可以在mat-slide-toggle
上使用change
方法作为
<mat-slide-toggle
(change)="changeDisable()" formControlName="enableWifi">
Enable Wifi</mat-slide-toggle>
<mat-form-field class="demo-full-width">
<input [disabled]="checked" formControlName="FirstName" matInput
placeholder="First Name">
</mat-form-field>
changeDisable() {
if (this.formGroup.controls['FirstName'].disabled) {
this.formGroup.controls['FirstName'].enable() ;
} else {
this.formGroup.controls['FirstName'].disable() ;
}
}
请试试这个
在 HTML 中:
<mat-slide-toggle (change)="toggle($event)">Slide me!</mat-slide-toggle>
<input [attr.disabled]="show ? '' : null"/>{{show}}
在 ts:
show: boolean = false;
toggle(e: any) {
e.checked? this.show = true: this.show = false;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.