Difference between 2 type of displaying data in Angular 2

前端 未结 2 1639
天命终不由人
天命终不由人 2021-01-25 07:19

I have some Angular2 code:


and


Note:

相关标签:
2条回答
  • 2021-01-25 08:02

    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.

    0 讨论(0)
  • 2021-01-25 08:11

    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

    • What's the difference between `value="{{todo.title}}"` and `[value]="todo.title"`?
    • Angular 2 Template Syntax
    0 讨论(0)
提交回复
热议问题