Эти отображаются, чтобы работать одинаково. Но так ли они? (Примечание $ scope.active)Свойства, которые зависят от другого объекта с проверкой
Первый один:
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);
}]);