如何使用angular2/4材质更改单击事件上的材质图标? [英] How to change material-icon on click event with angular2/4 material?

查看:31
本文介绍了如何使用angular2/4材质更改单击事件上的材质图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 md-tab-group 中有以下图标:

I have the following icon within md-tab-group:

<md-tab-group>
  <md-tab *ngFor="let tab of arrayOfTabs">
    <ng-template md-tab-label>
        <md-icon (click)="changetab()">close</md-icon>
    </ng-template>
    My Tab Content
</md-tab>
</md-tab-group>

我想让它不是关闭"材质图标,而是将其更改为星形"图标.我如何通过点击该特定选项卡图标上的事件来实现这一点?

I want to make it so that instead of the "close" material icon, change it to a "star" icon. How can I accomplish that through a click event on the icon for that specific tab?

推荐答案

在组件中:

public icon = 'close'; 

public changeIcon(newIcon: string ){
    this.icon = newIcon ; 
}

在 HTML 中

<md-icon (click)="changeIcon('star')>{{icon}}</md-icon>

这篇关于如何使用angular2/4材质更改单击事件上的材质图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆