Difference between [] and {{}} for binding state to property?

前端 未结 3 605
梦毁少年i
梦毁少年i 2020-12-16 13:08

Here is an template example:



Here b

3条回答
  •  既然无缘
    2020-12-16 13:52

    I'm coming a little bit late after the battle :) , but , in my understanding , there is another difference which can sometimes be very important . As its name implies "Property Binding" means that you are binding to the property of the HTML element "object"(which corresponds to its "objective" representation in the DOM) , wihch is a different thing from string interpolation , which can be applied to the HTML element tag attribute, and which is the reason why you can only put strings in it , as you are talking to a not parsed/parseable entity.

    Very often , you have a direct correspondance between both (the tag in your html has a foo attribute , which is linked to the foo property of the DOM object) , but that's not a rule and you can have attributes that are not linked to properties as well as the opposite.

    By the way , you have a very good answer in stack overflow which explains deeply the difference between both : What is the difference between properties and attributes in HTML?

提交回复
热议问题