ng-view 未加载模板(无网络服务器 运行)
ng-view not loading the template (no web server running)
类似问题的所有答案我都试过了,都没有成功。我有一个这样的项目目录结构:
应用程序
config.js
- 共享
Layout.html
- 首页
Index.html
这里config.js,Shared和Home在同一层级。
我的 Layout.html 有代码:
<!DOCTYPE html>
<html ng-app="app">
<head>
<script type="text/javascript" src="../Assets/ng/angular/angular.js"></script>
<script type="text/javascript" src="../Assets/ng/angular-route.js"></script>
<script type="text/javascript" src="../config.js"></script>
</head>
<body>
<a href="#/">Home</a>
<section ng-view></section>
</body>
</html>
我的Index.html只有"Home view".
config.js 文件:
angular.module("app", ['ngRoute')
.config(['$routeProvider', function($routeProvider){
$routeProvider
.when('/', {
templateUrl: '../Home/Index.html'
})
.otherwise({
redirecTo: '/'
});
}]);
然而,这在 <section></section>
中没有显示任何内容。没有抛出异常。顺便说一句,我不是 运行 网络服务器。我只是在 Chrome 中打开我的 Layout.html,然后单击 link,但模板没有加载。
在浏览器中 Chrome url 打开页面时是这样的
file:///Users/user.name/Desktop/folder1/subfolder1/app/Shared/Layout.html#/
我的方法有什么问题?谢谢。
兄弟,请使用本地服务器加载您的应用程序。使用 visual studio 或者如果你知道 nodejs 而不是使用它。
您正在直接从文件系统加载它。
类似问题的所有答案我都试过了,都没有成功。我有一个这样的项目目录结构:
应用程序
config.js
- 共享
Layout.html
- 首页
Index.html
- 共享
这里config.js,Shared和Home在同一层级。
我的 Layout.html 有代码:
<!DOCTYPE html>
<html ng-app="app">
<head>
<script type="text/javascript" src="../Assets/ng/angular/angular.js"></script>
<script type="text/javascript" src="../Assets/ng/angular-route.js"></script>
<script type="text/javascript" src="../config.js"></script>
</head>
<body>
<a href="#/">Home</a>
<section ng-view></section>
</body>
</html>
我的Index.html只有"Home view".
config.js 文件:
angular.module("app", ['ngRoute')
.config(['$routeProvider', function($routeProvider){
$routeProvider
.when('/', {
templateUrl: '../Home/Index.html'
})
.otherwise({
redirecTo: '/'
});
}]);
然而,这在 <section></section>
中没有显示任何内容。没有抛出异常。顺便说一句,我不是 运行 网络服务器。我只是在 Chrome 中打开我的 Layout.html,然后单击 link,但模板没有加载。
在浏览器中 Chrome url 打开页面时是这样的
file:///Users/user.name/Desktop/folder1/subfolder1/app/Shared/Layout.html#/
我的方法有什么问题?谢谢。
兄弟,请使用本地服务器加载您的应用程序。使用 visual studio 或者如果你知道 nodejs 而不是使用它。 您正在直接从文件系统加载它。