angularjs – 加载ng-includes时是否有$routechangesuccess或$viewcontentloaded事件?

我试过了

> $stateChangeSuccess,
> $routeChangeSuccess,和
> $viewContentLoaded

但我无法让我的自定义jQuery init函数在我的ng-include加载后运行,或者如果我在ng-swith之后切换它.

Index.html具有ng-view到dashboard.html,其中包含此代码.

    <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有一个控制器,有这个

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

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

在ng-switch加载ng -inc后,如何才能触发我的jquery函数?

最佳答案 这应该是$viewContentLoaded和includeContentLoaded

查看ngInclude的事件

https://docs.angularjs.org/api/ng/directive/ngInclude

点赞