考虑this plunker 。我认为我已正确设置所有内容,但我的模板未使用 ng-view
指令加载到 div 中。
我的路线已配置:
routes.forEach(function (r) {
$routeProvider.when(r.url, r.templateUrl);
});
$routeProvider.otherwise({ redirectTo: '/' });
我的路线是:
return [
{
url: '/',
templateUrl: 'main.html'
}, {
url: '/games',
templateUrl: 'games.html'
}
];
首先,我的导航似乎不起作用,而且,即使我位于根目录中(当路径为 /
时),我的 main.html 模板也不起作用加载到 ng-view 中。谁能准确地看出我做错了什么?
最佳答案
函数定义为:
when(path, route);
其中
route
是一个对象
:routes.forEach(function (r) { $routeProvider.when(r.url, { templateUrl: r.templateUrl }); });
将
href
更改为:<li><a href="#/">Main</a></li> <li><a href="#/games">Games</a></li>
关于javascript - ng-view 未填充模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23843969/