我正在尝试为我的项目添加一些路由。我正在使用Angular 1.3.0的基本角度路径
app.js文件:
foreach
index.html文件:
'use strict';
var routerApp = angular.module('mcw', [
'ngRoute',
'mcw.controllers',
'directives',
'filters',
'mcw.services']);
routerApp.config(function ($routeProvider) {
$routeProvider
.when('/', {templateUrl: 'index.html', controller: 'LoginController'})
.when('/Home', {templateUrl: 'templates/home.html', controller: 'ResourcesController'})
.otherwise({redirectTo: '/'});
});
我使用'python -m http.server'(Python 3.4.3)作为服务器,以及。的URL “127.0.0.1:8000/”,“127.0.0.1:8000 / index.html”,“127.0.0.1:8000 / index.html#/ Home”全部转到index.html页面。
答案 0 :(得分:5)
您在页面上错过了ng-view
指令,该指令从$routeProvider
和template
&指定的controller
将加载到ng-view
元素中。
将其添加到正文
中<body>
<ng-view></ng-view>
</body>
答案 1 :(得分:1)
是的,你需要在体内进行ng-view。
在我的视图中,只有你在ng-view标签内加载的内容不应该是index.html。 (但您想要放在ng-view标签内)。 index.html应该是放置ngview的页面。加载其他html文件(在ng-view标签中)
它的工作方式是&#39;指令&#39;将被放置在ng-view标签内。 (更具体地说,是您在路由器{.when}对象中键入的html文件。 在您的情况下:templates / home.html以及您所谓的index.html
Foo
如果您愿意,甚至可以在其中使用带有ng-view的div。 (我推荐第一种方法)