在 Angular 中,在资源服务填充多个模型后触发代码的最佳实践是什么。嵌套 $scope.$watch?
现在,我正在作弊并检查数组中的值,这感觉不是很“有棱角”。
$scope.loaded = [];
$scope.modelA = aResource.query({}, function() {$scope.loaded.push('a')});
$scope.modelB = bResource.query({}, function() {$scope.loaded.push('b')});
$scope.$watch(loaded.length, function(newValue) {
if ($scope.loaded.indexOf(modelA) != -1 && $scope.loaded.indexOf(modelB) != -1) {
console.log('done!');
}
});
https://groups.google.com/forum/?fromgroups=#!topic/angular/TizlifUL7FU