我是新的这个角世界,我有点困惑与使用双花括号{{}}
和单个花括号{}或有时没有大括号用于包括表达式,如在指令
和单个花括号{}或有时没有大括号用于包括表达式,如在指令
> ng-class = {expression}
>正常数据绑定,如{{obj.key}}
> ng-hide =’mydata ===“red”’
{{}} – 双大括号:
{{}}是Angular表达式,并且当你想要写HTML东西时会非常方便:
<div> {{planet.name == "Earth" ? "Yeah! We 're home!" : "Eh! Where 're we?"}} </div> <!-- with some directives like `ngSrc` --> <img ng-src="http://www.example.com/gallery/{{hash}}"/> <!-- set the title attribute --> <div ng-attr-title="{{celebrity.name}}">... <!-- set a custom attribute for your custom directive --> <div custom-directive custom-attr="{{pizza.size}}"></div>
不要在已经是表达式的地方使用它们!
例如,指令ngClick将写在引号之间的任何内容视为表达式:
<!-- so dont do this! --> <!-- <button ng-click="activate({{item}})">... -->
{} – 单花括号:
{}因为我们知道代表JavaScript中的对象。在这里,也没有什么不同:
<div ng-init="distanceWalked = {mon:2,tue:2.5,wed:0.8,thu:3,fri:1.5,sat:2,sun:3}">
有一些指令,如ngClass或ngStyle接受地图:
<span ng-style="{'color' : 'red'}">{{viruses.length}} viruses found!</span> <div ng-class="{'green' : vegetable == 'lettuce','red' : vegetable == 'tomato'}">..
无花括号:
正如已经提到的,在内部表达式中去无支架。非常简单:
<div ng-if="zoo.enclosure.inmatesCount == 0"> Alarm! All the monkeys have escaped! </div>