0
我正在用angularjs编写一个应用程序,我不知道如何访问我的主控制器中的变量。
gsg_main.controller('mainCtrl',['$scope','SessionService','$http','$routeParams','MessageService','$interval','$location','orderByFilter',function($scope,SessionService,$http,$routeParams,MessageService,$interval,$location,orderBy){
//variablen
var self = this;
self.username = "any_name";
欲从嵌套控制器访问用户名:
gsg_main.controller('testCtrl',['$scope',function($scope){
var self = this;
self.testvar = $scope.$parent.username;
}]);
我也试过:
self.testvar = $scope.$parent.parent.username;
这是我在其他帖子找到。
有没有在主控制器中使用$ scope的方法?
感谢您的帮助。
你可以始终使用服务来共享控制器之间的值。 – Lex