angulardata-bindingattr

What is difference between binding to attribute and binding to property in Angular?


I understand that when we bind to data attributes, we need to use the syntax [attr.data-something]="expression" But why do we need to bind to, for example, id, title, name in the same way? Doesn't binding to a property (without attr.) give the same result?

<input type="text" [attr.title]="expression" />
<input type="text" [title]="expression" />

Asking because I saw this in the source code of some popular projects. For example PrimeNG:

enter image description here

Couldn't find a clear answer anywhere


Solution

  • You will have a behaviour difference when used on an Angular component.