How to nest ng-view inside ng-include?

后端 未结 1 945
逝去的感伤
逝去的感伤 2021-01-17 10:23

When trying to add an ng-view inside an ng-include, nothing happens. e.g. in the following code, when themes/midnight/index.html holds an

相关标签:
1条回答
  • 2021-01-17 11:03

    This problem occurs due a delayed instantiation of ng-view (passing through ng-include). In such case the $route instantiation is delayed as well, and $route will miss the location change event (and routing will not be performed at all).

    To bypass this, invoke the $route update function on application initialization:

    yourApp.run(['$route', function($route)  {
      $route.reload();
    }]);
    

    Further more, it is sufficient to only include $route as a dependency. This will work, too:

    yourApp.run(['$route', angular.noop]);
    

    Source: the related issue on github.


    Also check out ui-router, which is intended to specifically deal with the issue of nested views.

    0 讨论(0)
提交回复
热议问题