我有2个控制器MainCtrl
和IndexCtrl
。
我无法从IndexCtrl
访问功能中分配的值。有人有同样的问题吗?
function MainCtrl($scope, $location){
$scope.test = 'test';
function onComplete(user) {
$scope.user = user;
$location.path('/secondDirection');//IndexCtrl is acting here
}
}
function IndexCtr($scope, $controller) {
$controller('MainCtrl', {$scope:$scope} //I inherit my MainCtrl scope
$scope.test //test;
$scope.user //undefined
}
答案 0 :(得分:0)
尝试angular.extend子控制器
function IndexCtr($scope, $controller){
angular.extend(this,$controller('MainCtrl', {$scope:$scope})) //I inherit my
$scope.test //test;
$scope.user //undefined
}