end_lesslove2012
end_lesslove2012

Reputation: 107

Difference between 2 type of displaying data in Angular 2

I have some Angular2 code:

<img [src]="value">

and

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

Note: value is a property component

I tested myself and the result is the same, so what is the difference between them ?

Upvotes: 1

Views: 109

Answers (2)

yurzui
yurzui

Reputation: 214175

They are both properties bindings

Interpolation

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

is just sugar for

<img [src]="interpolate(value)">

So the difference between those expressions is that the value in the interpolation src="{{value}}" is always stringified while the value of basic property binding [src]="value" is passed as is.

See also

Upvotes: 2

micronyks
micronyks

Reputation: 55443

1) NOTE : don't use "" & {{}} together else value will be stringified.

src="{{value}}" 

value will always be stringified.


2)

Here, value is an expression which will be evaluated for the property binding.

[src] to be precise, this is an angular2 way property binding syntax.

 <img [src]="value">

So, it will bind value's evaluated value to src property.

Upvotes: 0

Related Questions