Home > database >  Dynamic title in Angular
Dynamic title in Angular

Time:07-28

I have this <i> tag

 <i  [ngClass]="{'yellow' : data.isLiked}" (click)="Like(data)"
 aria-hidden="true" title="Liked"></i> 

I have this data.isLiked is true then yellow class is added but i want to change the title also

if isLiked true then title should be Unlike otherwise Like

CodePudding user response:

You can do it by binding your title attribute to angular, like this:[title]=" data.isLiked ? 'Liked' : 'Unliked' "

Example:

<i  [ngClass]="{'yellow' : data.isLiked}" (click)="Like(data)"
 aria-hidden="true" [title]=" data.isLiked ? 'Liked' : 'Unliked' "></i> 
  • Related