What's the difference between `value=“{{todo.title}}”` and `[value]=“todo.title”`?

前端 未结 2 1019
闹比i
闹比i 2020-12-19 10:51

I have been doing a todo app in Angular 2 to graps the concepts... What\'s the difference between value=\"{{todo.title}}\" and [value]=\"todo.title\"

2条回答
  •  悲哀的现实
    2020-12-19 11:35

    Let's say we have this data

    todo = {
      title: 5
    };
    

    1) value="todo.title" - the attribute with name value and value "todo.title" (string)

    2) value="{{todo.title}}" - the property with name value and value "5" (always string)

    template_parser.ts method _parseAttr

    Therefore it won't be included as the attribute

    3) [value]="todo.title" - the property with name value and value 5 (number)

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

提交回复
热议问题