简体   繁体   English

angularJs中的一种方式和两种方式的数据绑定

[英]one way and two way data binding in angularJs

while building a very large scale angular application i came across a performance issue. 在构建大型角度应用程序时,我遇到了性能问题。 all my components and views heavily depend on data bindings, there ng-repeats everywhere. 我所有的组件和视图都严重依赖于数据绑定,到处都有ng-repeats。 so i decided to remove all the 2 way databindings by adding {{::scopevariableName}} , now since there is no 2 way data binding my question is will the view update if modal value is changed in the controller? 所以我决定通过添加{{::scopevariableName}}来删除所有2种方式的数据绑定,现在由于没有2种方式的数据绑定,我的问题是,如果在控制器中更改模态值,视图是否会更新?

function myCtr(){
   var that=this;
   this.scopevariableName='hannad'
   this.someFunction=function(){
     someEvent(function(callbackData){
        if(callbackData){
           that.scopevariableName='new value for scope variable'
       }
  });
 }
}


<p ng-bind="::$ctrl.somevariableName"></p>

from the docs: One-time expressions will stop recalculating once they are stable, which happens after the first digest if the expression result is a non-undefined value. 来自文档:一次性表达式一旦稳定就会停止重新计算,如果表达式结果为非不确定值,则在第一次摘要后会发生。

My understanding of one-time binding is after the first initialization of the scope variable if the object value changes the view will NOT change. 我对一次性绑定的理解是在范围变量的第一次初始化之后,如果对象值更改,则视图将不会更改。 because the watchers are not in effect. 因为观察者无效。 ex

$scope.myVar=null;
<p>{{::myVar}}</p>

if the there are any changes to $scope.myVar those will not effect in the view because it will take only its first initialization value. 如果$scope.myVar有任何更改, $scope.myVar这些更改不会在视图中生效,因为它将仅采用其第一个初始化值。 thats null. 多数民众赞成在空。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM