title: how to execute ng-init in angularJS everytime the route changes
body: <p>I have index file</p>
  <pre><code>  &lt;div ng-app=&quot;myApp&quot;  data-ng-init=&quot;init()&quot;&gt;
             
           &lt;ng-view&gt;&lt;/ng-view&gt;
             
      &lt;/div&gt;
  </code></pre>
  <p>script looks like this</p>
  <pre><code> var app = angular.module('myApp',  ['ngRoute'])
      
          app.config(function ($routeProvider, $locationProvider)
           {  
              $locationProvider.html5Mode(true);
              $routeProvider
              .when('/home/', 
                 {  
                    template: 'home.html',
                    controller: 'homeController' 
                }) .
              when('/menu/', 
             {  
                  templateUrl: 'menu.html',  
                  controller: 'menuController'  
              })
  
     app.controller('homeController',function($scope,$rootScope){
       $scope.init=function(){
           alert('executing the init function')
           }
         })
     app.controller('menuController',function($scope,$location){
         if($scope.var1){
         $location.path('/home/')
         }
      })
  </code></pre>
  <p>the first time the path is /home/ the alert is triggered.but from the menu controller when the variable <strong>var1</strong> is <strong>true</strong> then path is changed to <strong>/home/</strong> again but the init function is not running and alert is not triggered. how can this be fixed. i want the init in homecontroller to run everytime the path is changed to <strong>/home/</strong></p>