不能在angular的一个控制器中使用$rootScope、$compile和$route调用另一个控制器


 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,我怎么调用呢

angularjs中的控制器是不能在彼此之间使用的。对于这些功能,包装工厂或服务中需要的所有公共代码(服务是单例的,在整个应用程序中存在),并将服务注入到两个控制器中。

得到答案:

在appune .js中添加依赖项

美元的位置然后

mainApp.run(function($rootScope, $rootScope, $window,$location){
$location.path('/');
});

相关内容

最新更新