0

I need to bind data to HTML element i:

<i data-count="{{notificationsLength}}" class="fas fa-bell notification-icon" aria-label="Nofitication centre"></i>

I get error message: Can't bind to 'count' since it isn't a known property of 'i'.

Then I tried:

<i (data-count)="{{notificationsLength}}" class="fas fa-bell notification-icon" aria-label="Nofitication centre"></i>

but with the same result.

Thanks for help.

Peter Valek
  • 77
  • 1
  • 2
  • 9

2 Answers2

1

You can use [attr.*] syntax (without curly braces).

<i [attr.data-count]="notificationsLength" class="fas fa-bell notification-icon" aria-label="Nofitication centre"></i>

For further reading:

https://angular.io/guide/template-syntax#attribute-class-and-style-bindings

Harun Yilmaz
  • 7,773
  • 3
  • 24
  • 33
0

Use attribute binding syntax instead

<i  [attr.data-count]="notificationsLength" class="fas fa-bell notification-icon" aria-label="Nofitication centre"></i>

You can also use it this way

<i  attr.data-count="{{notificationsLength}}" class="fas fa-bell notification-icon" aria-label="Nofitication centre"></i>
Thanveer Shah
  • 3,065
  • 2
  • 12
  • 28