【发布时间】:2017-03-15 18:10:56
【问题描述】:
appscript.js
var myApp=angular.module('myApp',['ngRoute']);
myApp.config([$routeProvider,function($routeProvider) {
$routeProvider
// route for the home page
.when('/home', {
templateUrl: 'home.html',
controller: 'homeController'
})
// route for the about page
.when('/services', {
templateUrl: 'services.html',
controller: 'servicesController'
})
// route for the contact page
.when('/contacts', {
templateUrl: 'contacts.html',
controller: 'contactsController'
})
.otherwise({ redirectTo: '/services' });
}
]);
index.html
<!doctype html>
<html ng-app="myApp">
<head >
<script src="appscript.js"></script>
<link href="Styles/Styles.css" rel="stylesheet">
<script src="homeController.js"></script>
<script src="servicesController.js"></script>
<script src="contactsController.js"></script>
<script src="aboutController.js"></script>
<script src="clientsController.js"></script>
<script src="angular-route.min.js"></script>
<script src="angular.min.js"></script>
</head>
<body >
<div class="header" > <h2 style="color:blue;">Training Institute</h2>
</div>
<div class="nav">
<a href="#/home">Home</a>
<a href="#/about">About</a>
<a href="#/services">Services</a>
<a href="#/clients">Clients</a>
<a href="#/contacts">Contact</a>
</div>
<div class="content" >
<ng-view> </ng-view>
</div>
<div class="footer">footer</div>
</body>
</html>
homeController.js
angular.module('myApp').controller('homeController',function($scope)
{
$scope.message="i am in home controller";
}
);
home.html
<div>i am in home partial template</div>
我已经搜索了相关问题并做了很多更改,但仍然无法在视图中加载部分模板。网址已更改,但视图没有更新。
我将所有代码文件放在 index.html 所在的同一位置,以确保问题不是因为路径不正确。
【问题讨论】:
-
你用的是什么版本的angularjs?
-
我在 appscript.js 文件中引用了 v1.6.3
-
尝试像这样重新排序 head 标签中调用的脚本 .. angular.min --> angular-route --> appscript --> controllers
-
这听起来像是我回答的 stackoverflow.com/questions/42816212/… 的副本。你能检查那里提供的答案吗?
-
@ModarNa 我尝试重新订购,它解决了控制器消息显示的问题,但没有加载模板。