栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

角度JS中的双花括号和单花括号之间的区别?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

角度JS中的双花括号和单花括号之间的区别?

{{}}-双大括号:

{{}}
是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->{{viruses.length}} viruses found!</span><div ng->..

没有花括号:

如前所述,在表达式内部时要毫不留情。非常简单:

<div ng-if="zoo.enclosure.inmatesCount == 0">    Alarm! All the monkeys have escaped!</div>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/399638.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号