Javascript Angularjs app.run不';t载荷

Javascript Angularjs app.run不';t载荷,javascript,angularjs,Javascript,Angularjs,我对app.run()有问题。在主页中,app.run()正在工作。当我单击菜单按钮Events时,页面Events.html app.run()不起作用。但当我重新加载此页面时,app.run()正在工作。我不知道该怎么办。页面main.html和events.html在ngView中,菜单也在ngView中。 controller.js afroEarthApp.config(['$routeProvider', function($routeProvider){ $routePro

我对app.run()有问题。在主页中,app.run()正在工作。当我单击菜单按钮Events时,页面Events.html app.run()不起作用。但当我重新加载此页面时,app.run()正在工作。我不知道该怎么办。页面main.html和events.html在ngView中,菜单也在ngView中。
controller.js

afroEarthApp.config(['$routeProvider', function($routeProvider){
    $routeProvider
      .when('/',{
        templateUrl:'template/home.html',
        controller:'afroEarthMainCtrl'
      })
      .when('/events',{
        templateUrl:'template/events.html',
        controller:'eventsCtrl'
      })
      .when('/sites/:niche', {
        templateUrl:'template/single.html',
        controller:'SingleCtrl'
      })
      .otherwise({
        redirectTo: '/'
      })
}]);
afroEarthApp.controller('afroEarthMainCtrl',['$scope','$http','$location','$cookies', '$rootScope', '$route', function($scope, $http, $location, $cookies, $rootScope, $route) {
...some code...
}]);

afroEarthApp.controller('eventsCtrl',['$scope','$http','$location','$cookies', '$rootScope', '$route', function($scope, $http, $location, $cookies, $rootScope, $route) {
...some code...
}]);

afroEarthApp.run(['$log', '$rootScope', '$route', function ($log, $rootScope, $route) {
    $rootScope.$on('$viewContentLoaded', function ($rootScope, $route) {
...some code...
})
}]);
home.html

        <ul class="nav navbar-nav navbar-right">
            <li><a class="page-scroll" href="#websites">Lifestyle sites</a></li>
            <li><a class="page-scroll" href="stories">Success Stories</a></li>
            <li><a href="#/events" data-target="#events" target="_self">Events</a></li>
            <li><a class="page-scroll" ng-href="http://{{singleNiche.url}}.afroearth.com/login/">Login</a></li>
            <li class="other-countries">
                <a href="#">
                    {{singleNiche.country}}<img src="{{singleNiche.countryFlag}}"><i class="icon-caret-down"></i>
                </a>
                <ul>
                    <li ng-repeat="country in singleNiche.countries"><a ng-click="setCountry(country.url)" >{{country.name}}</a></li>
                </ul>
            </li>
        </ul>
    • {{country.name}

你能帮我吗。

在你的应用程序中添加以下内容。运行

 $rootScope.$on('$locationChangeStart', function (event, nextLocation, currentLocation) {
//your code here
});

此函数将在每次url更改时调用。

run块仅在应用程序启动时执行一次,因此它在重新加载时工作。这就是angular run:)仅在angular加载时调用run函数。确定。我该怎么办?在app.run中为所有控制器运行代码。
afroEarthApp.run(['$log','$rootScope','$route',函数($log,$rootScope,$route){$rootScope.$on('$locationChangeStart',函数(事件,下一个位置,当前位置){$rootScope.$on('$viewContentLoaded',函数($rootScope,$route){
我这样添加,但仍然不起作用。