如果我 运行 ng-repeat 对象或 returns 对象的函数有什么区别(性能)
Is there any difference (performance) if I run ng-repeat over object or function that returns object
我将服务中的一个数组绑定到 控制器 中的本地范围(通过引用传递):
myApp.controller('TheController', function($scope, theService){
$scope.theArray = theService.array;
})
在役:
//...
theService.array = [];
$http.get('/array').then(function(data){
theService.array = angular.extends(theService.array, data);// here I'm updating theService.array with new values;
})
该绑定的问题是我无法中断 对初始数组的引用。所以我必须做一些额外的功能来检测新旧数组之间的区别。
解决方法是每次都初始化数组,return 我的 service:
中的一个函数
$http.get('/array').then(function(data){
theService.array = data;
})
theService.getArray = function(){
return theService.array;
};
在控制器中它将是:
myApp.controller('TheController', function($scope, theService){
$scope.theArray = theService.getArray;
})
在我的 html(这里是问题)中,我将有:
<div ng-repeat="data in theArray()">....</div>
而不是<div ng-repeat="data in theArray ">....</div>
ng-repeat 的性能有问题吗?
我将服务中的一个数组绑定到 控制器 中的本地范围(通过引用传递):
myApp.controller('TheController', function($scope, theService){
$scope.theArray = theService.array;
})
在役:
//...
theService.array = [];
$http.get('/array').then(function(data){
theService.array = angular.extends(theService.array, data);// here I'm updating theService.array with new values;
})
该绑定的问题是我无法中断 对初始数组的引用。所以我必须做一些额外的功能来检测新旧数组之间的区别。
解决方法是每次都初始化数组,return 我的 service:
中的一个函数$http.get('/array').then(function(data){
theService.array = data;
})
theService.getArray = function(){
return theService.array;
};
在控制器中它将是:
myApp.controller('TheController', function($scope, theService){
$scope.theArray = theService.getArray;
})
在我的 html(这里是问题)中,我将有:
<div ng-repeat="data in theArray()">....</div>
而不是<div ng-repeat="data in theArray ">....</div>
ng-repeat 的性能有问题吗?