javascript - 如何根据 typescript 显示的动态条件更改图标?

标签 javascript angular typescript command-line-interface

我正在使用 Material 图标的名称通过 typescript 显示图标。我想根据条件更改图标。 就像在 typescript 中一样,图标的名称是“power_off”, 如果 power 为 false,那么我们要使用“power_off”,但如果 power 为 true,那么我们要使用“power”。 我正在为此类代码使用另一个组件,但它与该组件相连,并且该组件中的名称正在更改,但在 View 中它没有更改。 这个你能帮我吗。 提前谢谢你。

{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'}

最佳答案

希望对你有帮助👍

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

关于javascript - 如何根据 typescript 显示的动态条件更改图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55393222/

相关文章:

java - 通过 Java ScriptEngine 在 JavaScript 中使用 jar

javascript - 在 TypeScript 和 Angular2 中将部分返回的 json 数据分配给数组

html - 如何向 NgZorro Collapse header 组件添加关闭按钮?

javascript - 有没有一种简单的方法将复杂的 JS 对象转换为查询参数?

javascript - 鼠标悬停在节点上时显示自定义工具提示(力导向 d3 图)

angular - RxJS 订阅未触发

html - 如何以 Angular 4 对齐左右文本 mat-card-header?

typescript - Angularjs 2.0 不加载 templateUrl

javascript - Angular 项目加载两次,但只是有时

javascript - 获取div未溢出部分的高度