$ controller继承的角度范围问题

时间:2015-03-18 09:33:19

标签: angularjs

我有2个控制器MainCtrlIndexCtrl

我无法从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
}

1 个答案:

答案 0 :(得分:0)

尝试angular.extend子控制器

function IndexCtr($scope, $controller){
   angular.extend(this,$controller('MainCtrl', {$scope:$scope}))  //I inherit my 
   $scope.test //test;
   $scope.user //undefined
}