Rav*_*dav 3 angular-material2 angular angular5
我无法使用 renderer2 禁用角度材质的选择下拉菜单。下面是我的代码
组件.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>
Run Code Online (Sandbox Code Playgroud)
组件.ts
constructor(public renderer: Renderer2) {}
@ViewChild('exLoc') exLoc: ElementRef;
functionToDisableDropDown() {
this.renderer.setAttribute(this.exLoc, 'disabled', 'true');
}
Run Code Online (Sandbox Code Playgroud)
正确的做法实际上是使用Renderer2。
禁用是一个属性,这就是它不适用于您的代码的原因。
正确代码:
this.renderer.setProperty(this.exLoc, 'disabled', true);
this.renderer.setProperty(this.exLoc, 'disabled', false);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7085 次 |
| 最近记录: |