我對angular js非常陌生。 我已經實現路由的角度JS,但它不重定向我我在route.js 這裏已經指出的網頁是代碼: Route.js路由在angularjs中不起作用
var sampleApp = angular.module('sampleApp', []);
sampleApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/getplaces', {
templateUrl: 'getplaces.html',
controller: 'ListCtrl',
}).
when('/getuncategorisedplaces', {
templateUrl: 'list.html',
controller: 'uncatCtrl'
})
.otherwise ({
redirectTo: '/getplaces'
});
}]);
Controller.js
function uncatCtrl($scope, $http) {
$http.get('http://94.125.132.253:8000/getuncategorisedplaces').success(function (data) {
$scope.places = data;
console.log(data);
}
)}
// get places
function ListCtrl($scope, $http) {
$http.get('http://94.125.132.253:8000/getplaces').success(function (data) {
$scope.places = data;
console.log("Successful")
console.log(data);
}
)}
HTML代碼包括NG視圖和HREF如HREF = 「#getplaces」
<body ng-app="sampleApp" >
<div class="container">
<div class="row">
<div class="col-md-3">
<ul class="nav">
<li> <a class= "linha" href="#getplaces"> Get places </a></li>
<li><a class= "linha" href="post.html"> Post a movie </a></li>
<li><a class= "linha" href="#getuncategorisedplaces">List of uncategorised places </a></li>
</ul>
</div>
<div class="col-md-9">
<div ng-view></div>
</div>
</div>
我已經添加了它,它不起作用。我正在使用的文件可以在「http://creative.coventry.ac.uk/~4078078/Test%20codes/index.html#/getuncategorisedplaces」 – butYouDontLookLikeADeveloper
檢查hrefs。將它們更改爲「/ getplaces」和「/ getuncategorisedplaces」。 – avidenic
我從#getplaces中將它們更改爲/ getplaces時出現錯誤,表示未找到 – butYouDontLookLikeADeveloper