简体   繁体   English

如何在 angular 中禁用 mat-icon?

[英]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 'disabled' since it isn't a known property of 'mat-icon') so how to show particular mat-icon disabled in angular 6?这里我有多个 mat-icons,删除命名的 mat-icon 我想禁用我在这个上使用禁用属性但它给出错误(无法绑定到'disabled'因为它不是'mat-的已知属性 - icon') 那么如何显示 angular 6 中禁用的特定 mat-icon?

<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>

Use mat-icon inside button tag and then you can use disabled在按钮标签内使用mat-icon ,然后您可以使用禁用

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使用 ngClass 指令添加禁用

<mat-icon color="warn" [ngClass]="{'disable':payloadArray.enabled !== true}"(click)="onClick()">delete</mat-icon>

Example: https://stackblitz.com/edit/angular-4jdvc9示例: https : //stackblitz.com/edit/angular-4jdvc9

Although late at the party I figured out the following CSS with [ngClass]="{'disable':condition...}"虽然在晚会上我想出了以下 CSS [ngClass]="{'disable':condition...}"

.disable:hover{
    cursor: not-allowed;
}
.disable:active{
    pointer-events: none;
}
mat-icon.disable {
    filter:opacity(0.5);
}

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>

I've found the source of this issue: Make sure that this line exists at your component code (mock.component.ts):我找到了这个问题的根源:确保这一行存在于您的组件代码 (mock.component.ts) 中:

import { MatButtonModule } from "@angular/material/button";`

And these lines present at your app module loader (app.module.ts):这些行出现在您的应用程序模块加载器 (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. PS:我对 <mat-button/> 也有同样的问题 - 类似的修复应该也适用于 <math-icon/> ,但你需要使用你的组件的名称而不是那里的按钮。

Here, You need to change use mat-icon inside the button在这里,您需要更改按钮内的 use mat-icon

<button mat-icon color="warn" style="cursor: pointer;"[disabled]="payloadArray.enabled != 'true' ">delete <button mat-icon color="warn" style="cursor: pointer;"[disabled]="payloadArray.enabled != 'true' ">删除

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM