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
  • 87
  • 1
  • 2
  • 11

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
  • 8,281
  • 3
  • 24
  • 35
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,250
  • 2
  • 15
  • 31