0

Is it possible to contitionally add the title="" attribute to a div? i want to make it look clean so i dont want to create a second div and using ngIf to hide one or the other.

My div looks like this and it should add a title if permission is true

<div (click)="goToChangelog()" [ngStyle]="{'cursor': (permission) ? 'pointer' : ''}">
    Version {{version}}
</div>

1 Answer 1

1

use :

[attr.title]="(permission) ? 'Go to Changelog' : ''"

In this example, if the permission variable is true, the div will have a title attribute with the value "Go to Changelog". If permission is false, the title attribute will not be added to the div.

And here's the official doc : https://angular.io/guide/attribute-binding

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.