search

Home  >  Q&A  >  body text

angular.js - Sometimes you need to add {{}} in the ng tag, sometimes you need {}, and sometimes you don’t need braces. Are there any rules?

To bind the value in $scope in ng-bind, you need to write {{}}
To bind the value in $scope in ng-src, you need to write {{}}
You don’t need to write {{}}
to determine true or false in ng-checked. In ng-class, you need to write {}

to determine true or false.

When do you need {{}} and when do you need {}? Are there any rules for this?

天蓬老师天蓬老师2827 days ago647

reply all(1)I'll reply

  • 迷茫

    迷茫2017-05-15 17:04:58

    You remember one thing, as long as it is ng-开关的指令,大都是不需要写的。ng-srcexcept.

    ng-src 为什么要呢?主要是因为不能直接用 src ,它会直接请求,不等待 Angular 解析 {{}} ,而 ng-src Mainly to achieve effects similar to this:

    <img ng-src="http://www.gravatar.com/avatar/{{hash}}" alt="Description" />

    So, that’s it.

    ng-class实际上是需要你提供一个对象,所以使用 {} to construct.

    reply
    0
  • Cancelreply