首页 > angularjs {{}}疑问

angularjs {{}}疑问

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

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

而我期望的是

html4

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


这是angularjs的基础知识,这是angularjs中数据绑定,它的表达式就是:{{}},去链接里面好好学学基础吧,http://www.hubwiz.com/course/547c3e3b88dba0087c55b4e5/


AngularJs ng-bind 输出的HTML值肯定不会单单是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


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


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

【热门文章】
【热门文章】