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:
Couldn't find a clear answer anywhere
You will have a behaviour difference when used on an Angular component.
[title]
will bind to the title
input if there is one but won't add the title attribute.[attr.title]
will only apply a title
attribute to your element.