How to Make Mat-Icon Disabled in Angular?
Here I Have Multiple Mat-Icons, Delete Named Mat-Icon I Want to Make Disabled I Use Disabled Properties on This but It Gives Error Like(Can't Bind to...
Here i have multiple mat-icons, delete named mat-icon i want to make disabled i use disabled properties on this but it gives error like(Can't bind to 'disabled' since it isn't a known property of 'mat-icon') so how to show particular mat-icon disabled in angular 6?
<mat-icon color="warn" style="cursor: pointer;" [disabled]="payloadArray.enabled != 'true' ">delete</mat-icon>
<mat-icon color="warn" style="cursor: pointer;">person_add</mat-icon>
6 Answers
Use mat-icon inside button tag and then you can use disabled
Try this,
<button mat-icon-button [disabled]="payloadArray.enabled != 'true' " color="primary" >
<mat-icon color="warn" style="cursor: pointer;" >delete</mat-icon>
</button>
Use ngClass directive to add disable
<mat-icon color="warn" [ngClass]="{'disable':payloadArray.enabled !== true}"(click)="onClick()">delete</mat-icon>
Example:
it's all post but what about two mat-icon?
<mat-icon *ngIf="payloadArray.enabled == 'true'"
color="warn" style="cursor: pointer;">
delete
</mat-icon>
<mat-icon *ngIf="payloadArray.enabled != 'true'"
"color="warn" style="opacity:.5">
delete
</mat-icon>
Although late at the party I figured out the following CSS with [ngClass]="{'disable':condition...}"
.disable:hover{
cursor: not-allowed;
}
.disable:active{
pointer-events: none;
}
mat-icon.disable {
filter:opacity(0.5);
}
I've found the source of this issue: Make sure that this line exists at your component code (mock.component.ts):
import { MatButtonModule } from "@angular/material/button";`
And these lines present at your app module loader (app.module.ts):
import { MatButtonModule } from '@angular/material/button';
@NgModule({
imports: [
MatButtonModule
],
*etc...*
})
PS: I had the same issue with <mat-button/> - the similar fix should work with <math-icon/> as well, but you need to use the name of your component instead of the button there.
Here, You need to change use mat-icon inside the button
<button mat-icon color="warn" style="cursor: pointer;"[disabled]="payloadArray.enabled != 'true' ">delete