首页 > 解决方案 > 如何根据通过打字稿显示的动态更改图标条件?

问题描述

我使用材料图标的名称通过打字稿显示图标。我想根据情况更改图标。就像在打字稿中说的那样,图标的名称是“power_off” if power is false then we want to use 'power_off' but if the power is true then we want to use 'power',。我正在为此类代码使用另一个组件,但它与该组件连接,并且该组件中的名称正在更改,但在视图中它没有更改。这个你能帮我吗。先感谢您。

{name: 'associateDriver', visible: true, tooltip: 'Associate Driver', icon: 'person', type: 'icon'},
                {name: 'associateServiceReminder', visible: true, tooltip: 'Service Reminder', icon: 'add_alert', type: 'icon'},
                {name: 'busStopStatus', visible: false, tooltip: 'Bus Stop Status', icon: 'pin_drop', type: 'icon'},
                {name: 'delete', visible: false, tooltip: 'Delete', icon: 'delete', type: 'icon'},
                {name: 'immobilize', visible: true, tooltip: 'Immobilize', icon: 'power_off', type: 'icon'}

标签: javascriptangulartypescriptcommand-line-interface

解决方案


我希望这有帮助

<div> 
  <mat-icon *ngIf="power">power_on<mat-icon>
  <mat-icon *ngIf="!power">power_off<mat-icon>
</div>

推荐阅读