{{}} - double curly braces:
{{}}
are Angular expressions and come quite handy when you wish to write stuff to 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>
Don't use these at a place that is already an expression!
For instance, the directive ngClick
treats anything written in between the quotes as an expression:
<!-- so dont do this! -->
<!-- <button ng-click="activate({{item}})">... -->
{} - single curly braces:
{}
as we know stand for objects in JavaScript. Here, too, nothing different:
<div ng-init="distanceWalked = {mon:2, tue:2.5, wed:0.8, thu:3, fri:1.5,
sat:2, sun:3}">
With some directives like ngClass
or ngStyle
that accept map:
<span ng-style="{'color' : 'red'}">{{viruses.length}} viruses found!</span>
<div ng-class="{'green' : vegetable == 'lettuce',
'red' : vegetable == 'tomato'}">..
no curly braces:
As already mentioned just go braceless when inside expressions. Quite simple:
<div ng-if="zoo.enclosure.inmatesCount == 0">
Alarm! All the monkeys have escaped!
</div>
?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…