Why do some attributes require the "attr." prefix and some don't?
Angular8: What is the difference between [attr.title]='myVar' and [title]='myVar'?
428 views Asked by Krishnabm At
1
Why do some attributes require the "attr." prefix and some don't?
Short answer:
[title]="myVar"is property binding whereas[attr.title]="myVar"is attribute binding.Attribute binding must be used, when DOM property doesn't exist. For example,
colspandoes not exist DOM property and you must useattr.colspan="...". When you try usecolspan="..."you get an error in console. Read up on attribute binding here.