我想在角js做路由和服務器運行良好。但角度路由不能正常工作,只有main.html頁面進入ng-view,second.html不會來。當點擊第一個和第二個HTML相同的mainController工作不是第二個控制器。角度路由不能正常工作?
HTML
<!Doctype html>
<html ng-app="myApp">
<meta charset=utf-8" />
<head>
<script src="http://code.angularjs.org/snapshot/angular.min.js"></script>
<script src="http://code.angularjs.org/snapshot/angular-route.min.js">
</script>
<script type="text/javascript"src="app.js"></script>
<body>
<header>
<li><a href="#/"><i></i>first</a></li>
<li><a href="#/second"><i></i>Second</a></li>
</header>
<div class = "container">
<div ng-view>
</div>
</body>
main.html中
<h1> this is main </h1>
second.html
<h1> this is second </h1>
app.js
var myApp = angular.module('myApp',['ngRoute']);
myApp.config(function ($routeProvider){
$routeProvider
.when('/',{
templateUrl: 'pages/main.html',
controller: 'mainController',
})
.when('/second',{
templateUrl: 'pages/second.html',
controller: 'secondController',
})
});
myApp.controller('mainController',
['$scope','$log','$location',function($scope,$log,$location){
$log.info($location.path());
console.log("first");
}]);
myApp.controller('secondController',
['$scope','$log','$location',function($scope,$log,$location){
$log.info($location.path());
console.log("second");
}]);
你在控制檯遇到錯誤? – Zooly
「secondController」在哪裏? –