【问题标题】:AngularJS template binding to objectAngularJS模板绑定到对象
【发布时间】:2019-02-25 20:53:58
【问题描述】:

众所周知,当我们像 {{ $ctrl.obj }} 这样绑定到模板中的变量时,AngularJS 使用最简单的 $watch 形式。
它应该通过引用比较$ctrl.obj 的值,但是如果我改变$ctrl.obj,则更改会反映在视图中。引用没有改变,为什么?

【问题讨论】:

  • 查看我的最新答案。你最后的评论让我意识到我之前的回答是错误的。 BTW,根据source codengBind指令不要使用第三个参数:相关部分是:scope.$watch(attr.ngBind, function ngBindWatchAction(value) { element.textContent = stringify(value); });

标签: angularjs angularjs-watch angularjs-bindings


【解决方案1】:

当我们使用方括号 ({{}}) 时,angular 不会使用任何 watch (ers) 来检测放置在其中的表达式的变化。相反,这个表达式被脏检查并在每个$digest 循环中刷新,即使没有必要。

看到这个帖子:AngularJS : Why ng-bind is better than {{}} in angular?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-30
    • 2017-07-05
    • 1970-01-01
    • 1970-01-01
    • 2014-11-03
    • 1970-01-01
    • 2017-05-09
    • 1970-01-01
    相关资源
    最近更新 更多