我无法使用renderer2禁用角度材质的选择下拉菜单。下面是我的代码
Component.html
<mat-select #exLoc (selectionChange)="someFun($event)" [(value)]="someVal">
<mat-option aria-selected="true" [value]="locVal" *ngFor="let location of locations">{{location.LocationName}}
</mat-option>
</mat-select>
Component.ts
constructor(public renderer: Renderer2) {}
@ViewChild('exLoc') exLoc: ElementRef;
functionToDisableDropDown() {
this.renderer.setAttribute(this.exLoc, 'disabled', 'true');
}
正确的方法实际上是使用Renderer2。
禁用是一个属性,这就是为什么它不能与您的代码一起使用的原因。
正确的代码:
this.renderer.setProperty(this.exLoc, 'disabled', true);
this.renderer.setProperty(this.exLoc, 'disabled', false);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句