これらは同じように機能するようです。しかし、それらは同じですか?($scope.active に注意)
最初の1つ:
angular.module('my.controllers', []).controller('MyController', ['$scope', 'myService',
function($scope, myService) {
$scope.myFilters = myService.myFilters;
$scope.active = $scope.myFilters.length > 0;
$scope.$watch(function() {
return myService.myFilters;
}, function(newFilters) {
$scope.myFilters = newFilters;
$scope.active = $scope.myFilters.length > 0;
},true);
}]);
二つ目:
angular.module('my.controllers', []).controller('MyController', ['$scope', 'myService',
function($scope, myService) {
$scope.myFilters = myService.myFilters;
$scope.active = function(){return $scope.myFilters.length > 0};
$scope.$watch(function() {
return myService.myFilters;
}, function(newFilters) {
$scope.myFilters = newFilters;
},true);
}]);