Is there a $ routechangesuccess or $ viewcontentloaded event when ng-includes loads?

I tried

  • $ stateChangeSuccess,
  • $ routeChangeSuccess and
  • $ viewContentLoaded

but I cannot run my custom jQuery initialization function after loading ng-include or if I switch it after the fact with ng-swith.

Index.html has an ng-view for dashboard.html that has this code.

    <div class="row">
    <div class="col-md-12">
        Switch Dashboard View: <input type="radio" name="dashboardView" value="0" ng-model="vm.dashboardView" />Franchisee | 
        <input type="radio" name="dashboardView" value="1" ng-model="vm.dashboardView" />Real Estate
    </div>
</div>
<!--tiles end-->
<div data-ng-switch="vm.dashboardView">
    <div data-ng-switch-when="0">
        <div data-ng-include="'/Views/Dashboard/FranchiseeDashboard.html'"></div>
    </div>
    <div data-ng-switch-when="1">
        <div data-ng-include="'/Views/Dashboard/RealestateDashboard.html'"></div>
    </div>
</div>

index.html has a controller that has this

  $rootScope.$on("$viewContentLoaded", function () {
        Interactions.init();

    });
    $rootScope.$on('$stateChangeSuccess',
       function (event, next, current) {
           Interactions.init();
       }
   );
    $rootScope.$on('$routeChangeSuccess',
       function (event, next, current) {
           Interactions.init();
       }
   );

How can I run the jquery function after ng-switch has loaded ng-include?

+4
source share
1 answer

This should work $ viewContentLoaded and includeContentLoaded Look at the events for ngInclude https://docs.angularjs.org/api/ng/directive/ngInclude

+2

Source: https://habr.com/ru/post/1548004/


All Articles