2016-04-07 16 views
0

Ich habe ein Problem mit app.run(). Auf der Hauptseite funktioniert app.run(). Wenn ich auf die Menüschaltfläche Ereignisse klicke und in der Seite events.html app.run() nicht funktioniert. Aber wenn ich diese Seite neu lade, funktioniert app.run(). Ich weiß nicht, was ich machen soll. Die Seiten main.html und events.html befinden sich in der ngView, das Menü befindet sich auch in der ngView.
controller.jsAngularjs app.run lädt nicht

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> 

Können Sie hepl mich bitte.

+4

run Block wird nur einmal beim Start Ihrer App ausgeführt, daher funktioniert es beim Nachladen. – webduvet

+0

Nun, Das ist die Art eckigen Lauf :) Die Funktion run wird nur aufgerufen, wenn eckig geladen ist. – IsraGab

+0

Ok. Was soll ich tun? Im app.run-Code für alle Controller. –

Antwort

0

die folgenden in Ihrem app.run

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

Diese Funktion auf jedem URL ändern rufen wird hinzuzufügen.

+0

'afroEarthApp.run ([$ log ',' $ rootScope ',' $ route ', Funktion ($ log, $ rootScope, $ route) { $ rootScope. $ On (' $ locationChangeStart ', Funktion (Ereignis, nextLocation, currentLocation) { $ rootScope. $ on ('$ viewContentLoaded', Funktion ($ rootScope, $ route) {'Ich habe so hinzugefügt, funktioniert aber immer noch nicht. –