如何巢NG-视图中NG-包括哪些内容? [英] How to nest ng-view inside ng-include?

查看:204
本文介绍了如何巢NG-视图中NG-包括哪些内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当试图添加一个内的 NG-视图 NG-包括,没有任何反应。例如在以下code,当的主题/午夜/ index.html的的持有 NG-视图,就不会有视图显示:

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 ng-view, no view is rendered:

<ng-include src="'themes/midnight/index.html'"></ng-include>

不过,如果我使用下面的code,该视图显示两次:

However, if I use the code below, the view shows twice:

<ng-include src="'themes/midnight/index.html'"></ng-include>
<div ng-view></div>

这是什么问题以及如何解决?

What is the problem and how can I resolve it?

推荐答案

发生此问题,因为通过 NG-视图(传递的延迟实例NG-包括)。在这种情况下, $路线实例被延迟,以及, $路线将错过位置变化事件(和路由将根本不执行)。

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]);

<分> 来源:在github 相关问题

还检查了 UI路由器 ,其目的是专门与处理嵌套意见的问题。

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

这篇关于如何巢NG-视图中NG-包括哪些内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆