加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 双和单个大括号在角JS之间的差异?

发布时间:2020-12-17 09:24:49 所属栏目:安全 来源:网络整理
导读:我是新的这个角世界,我有点困惑与使用双花括号{{}} 和单个花括号{}或有时没有大括号用于包括表达式,如在指令 ng-class = {expression} 正常数据绑定,如{{obj.key}} ng-hide =’mydata ===“red”’ {{}} – 双大括号: {{}}是Angular表达式,并且当你想要
我是新的这个角世界,我有点困惑与使用双花括号{{}}
和单个花括号{}或有时没有大括号用于包括表达式,如在指令

> 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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读