How to write data attributes using Angular?

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.