Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change material-icon on click event with angular2/4 material?

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?

like image 755
Rolando Avatar asked Jun 16 '17 03:06

Rolando


1 Answers

In component :

public icon = 'close'; 

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

In HTML

<md-icon (click)="changeIcon('star')>{{icon}}</md-icon>
like image 190
Vamshi Avatar answered Nov 16 '22 11:11

Vamshi