我有一个带有两个注入子控制器的父控制器,如下所示:
.controller('parentCtrl', ['$scope', '$http', '$controller', '$uibModal',
function ($scope, $http, $controller, $uibModal) {
$controller('firstChildCtrl', { $scope: $scope })
$controller('secondChildCtrl', { $scope: $scope })
}])
当用户注销时,登录控制器会发出注销事件:
$scope.$emit('logout');
所有其他控制器在收到此事件时清除其数据,如下所示:
$scope.initial = [];
$rootScope.$on("logout", function (event) {
$scope.activities = angular.copy($scope.initial);
});
所以我的问题是,如何让父控制器清除子范围内的数据(因为它不是这样做的)?
提前致谢!
答案 0 :(得分:0)
我最后做的是有一个控制器,工厂(获取数据的服务)在控制器外部,我将多个服务注入到我的控制器中。
.controller('multiCtrl', ['$scope', '$rootScope', '$http', '$uibModal', '$q', 'getApples', 'getPears',
function ($scope, $rootScope, $http, $uibModal, $q, getApples, getPears) {
var myApples = getMyApples.fetch(function (apples) {
$scope.apples = apples;
var theApples = $scope.apples;
});
var myPears = getMyPears.fetch(function (pears) {
$scope.pears = pears;
var thePears = $scope.pears;
});
});