angular when to use curly brackets

后端 未结 3 1606
失恋的感觉
失恋的感觉 2020-12-20 19:53

In angular sometimes i have seen curly brackets but some times not.i search a lot but i couldn\'t find correct question

with curly bracket

ng-src=\         


        
3条回答
  •  自闭症患者
    2020-12-20 20:30

    Beacuse they mean two different things. When you use this:

    
    

    This means that angular will go to the scope and get value from there with test as key. So value will be $scope.test. But attribte value will be "test"

    When you use

    ng-src="{{imageSrc}}
    

    then value will be evaluated and placed to the attribute. So value willbe $scope.imageSrc and attribute value will be $scope.imageSrc.

    But. Not all tags can wait for evaluation. They think that value {{}} is correct and will not be changed. This cause to bad request. To fix this problem ng-src was created.

提交回复
热议问题