angularjs {{}}疑问

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

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

而我期望的是

html4

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

阅读 6.8k
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。要不然输出值的位置如何控制?

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

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进