【发布时间】:2016-03-26 04:36:49
【问题描述】:
这是ng-include 在ng-view 输出中的结果:
当然,我只需要加载这个页面一次。
我的 app.js:
var app = angular.module('app', ['ngRoute']);
app.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/first_route', {
templateUrl: '/templates/first/index.html',
controller: 'FirstController',
controllerAs: 'First',
})
.when('/second_route', {
templateUrl: '/templates/second/index.html',
controller: 'SecondController',
controllerAs: 'Second',
});
// I omitted my app.run(), because it contains only headers and redirect to
// login page for not authenticated users
};
在我的主要index.html 文件中,我只使用ng-view 指令。
我的first/index.html 包含:
<h1>Current page</h1>
<ng-include src="'first/show.html'"></ng-include>
// remaining part of page
我的first/show.html 包含:
<ng-include src="'second/index.html'"></ng-include>
继续:我尝试按下一个顺序加载模板:
-
index.html(ng-view) -
first/index.html(ng-include) -
first/show.html(ng-include)
如何解决这个问题?
【问题讨论】:
-
你能用一个小程序重建这个问题吗?我在提供的代码/标记中看不到任何错误。
-
@null 我已将我的代码添加到 plunker,它工作正常 (plnkr.co/edit/XaPLhjQPUBgZZryzFW1U?p=preview)。看不懂,本地服务器的代码有什么问题,继续调试。
标签: angularjs ng-view angularjs-ng-include