Answers:
{{}}
是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
接受map的指令:
<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>