1
 mainApp
 .controller('homeController',
   function($scope, $http, $timeout, $compile, $rootScope, $routeParams, $location, $route) {
      //code goes here
   }
);

 mainApp.controller('ReportsController',
    function($scope, $http, $rootScope) {
       //another controller code goes here
    }
);

我将在reportsController页面重新加载时调用reportsController中的homeController,我该如何调用它?

4

2 回答 2

1

angularjs 中的控制器并不意味着可以相互使用。对于这些功能,将您需要的所有通用代码包装在工厂或服务中(服务是单例并存在于应用程序中)并将服务注入两个控制器。

于 2015-10-09T07:10:35.210 回答
0

得到答案:

在 apprun.js 中添加依赖

$location 然后

mainApp.run(function($rootScope, $rootScope, $window,$location){

$location.path('/');
});
于 2015-10-28T14:11:24.443 回答