Krishnabm
Krishnabm

Reputation: 185

Angular8: What is the difference between [attr.title]='myVar' and [title]='myVar'?

Why do some attributes require the "attr." prefix and some don't?

Upvotes: 0

Views: 541

Answers (1)

0x6368656174
0x6368656174

Reputation: 992

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, colspan does not exist DOM property and you must use attr.colspan="...". When you try use colspan="..." you get an error in console. Read up on attribute binding here.

Upvotes: 1

Related Questions