angular.js - angularjs {{}}疑问
PHPz
PHPz 2017-05-15 16:51:54
[AngularJS讨论组]

在html的界面中 {{a}}为什么输出的是

html<span class="ng-binding ng-scope">
4
</span>

而我期望的是

html4

是否有遇到过的大神帮忙解惑~

PHPz
PHPz

学习是最好的投资!

全部回复(4)
为情所困

引自官网:

The ngBind attribute tells Angular to replace the text content of the
specified HTML element with the value of a given expression, and to
update the text content when the value of that expression changes.

意思就是ngBind会告诉angular去将你写的表达式替换成一个特殊的html元素

而这个特殊的html元素就是那个带class的span了,

双花括号{{}}ngBind是一样的,实际上是一个directive,只在适用范围有稍许区别

官方文档ngBind

淡淡烟草味

AngularJs ng-bind 输出的HTML值肯定不会单单是4。要不然输出值的位置如何控制?

PHP中文网

a这个变量的值是怎么样被赋进去的?
一般来说$scope.a=4;
{{a}}的输出结果就是4的呀。

伊谢尔伦

谢邀。在angular的源码中可以看到 https://github.com/angular/angular.js/blob/master/src/ng/compile.js#L1...
其实就是为了给这个"顶级文本节点"绑定数据用的

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号