I am not able to disable the select dropdown of angular material using the renderer2. Below is my code
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');
}
The correct way to do it is actually to use Renderer2.
disabled is a Property that is why it is not working with your code.
Correct code :
this.renderer.setProperty(this.exLoc, 'disabled', true);
this.renderer.setProperty(this.exLoc, 'disabled', false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With