2016-04-07 10 views
0

私はapp.run()に問題があります。メインページでは、app.run()が動作しています。メニューボタンをクリックすると、イベントとページのevents.html app.run()は動作しません。しかし、このページをリロードすると、app.run()が動作しています。私は何をすべきかわからない。ページmain.htmlとevents.htmlはngViewにあり、メニューもngViewにあります。
controller.jsAngularjs app.runがロードされない

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> 

あなたは私をしてくださいheplことができます。

+4

runブロックはアプリの開始時に一度だけ実行されるため、リロード時に動作します。 – webduvet

+0

まあ、 これは、角度実行の方法です。 run関数は、angleがロードされている場合にのみ呼び出されます。 – IsraGab

+0

私は何をすべきか?すべてのコントローラのapp.runコード。 –

答えて

0

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

あなたapp.runに以下を追加します。この機能は、すべてのURLの変更を呼び出すになります。

+0

'afroEarthApp.run( '' $ log '、' $ rootScope '、' $ route '、function($ log、$ rootScope、$ route){ $ rootScope。$ on(' $ locationChangeStart '、function(イベント、 {$ viewContentLoaded '、function($ rootScope、$ route){'私はこのように追加しましたが、それでも動作しません。 –

関連する問題