Categories
Angular Answers

How to write data attributes using Angular?

Spread the love

Sometimes, we want to write data attributes using Angular.

In this article, we’ll look at how to write data attributes using Angular.

How to write data attributes using Angular?

To write data attributes using Angular, we can use the att attribute in our element.

For instance, we write

<ol class="viewer-nav">
  <li *ngFor="let section of sections" attr.data-value="{{ section.value }}">
    {{ section.text }}
  </li>
</ol>

to add the data-value attribute into our li elements with

attr.data-value="{{ section.value }}"

Conclusion

To write data attributes using Angular, we can use the att attribute in our element.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *