0

Is there a difference between these?

<img src="{{url}}">

<img [src]="url">

I know in AngularJS we had ng-src directive which was prefered to used to prevent loading image from {{url}} before angular takes over. Is this the same case?

1
  • It achieves the same result. [src] is not a known HTML attribute due to the []s, so the browser will not process it and will not make a request to the URL. It's really easy to try it out by just running the HTML you provided with different URLs and checking the network requests in your developer tools. Commented Dec 6, 2017 at 19:11

1 Answer 1

1
<img [src]="heroImageUrl"> 

is short of

<img bind-src="heroImageUrl"> 

this code will result same as <img src="{{url}}">. [src] this is for property binding. However when you need to bind some data to attribute you cannot use it. For example:

<td [attr.colspan]="1 + 1"> 

since colspan is not a property but html attribute.

Sign up to request clarification or add additional context in comments.

3 Comments

well seems like i am mistaken. <td colspan={{someVar}}> doesn't work as well.
after reding through docs I would expect it to work. Strange.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.