所以我在看的角度政黨成員和這個傢伙解釋「ngRoute」以及如何使用它,用這個例子:AngularJS:路由
var myApp = angular.module('myApp', ['ngRoute']);
myApp.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'pages/home.html',
controller: 'mainController'
})
.when('/second', {
templateUrl: 'pages/second.html',
controller: 'secondController'
})
});
myApp.controller('mainController', ['$scope', '$route', function ($scope, $route) {
}])
.controller('secondController', ['$scope', '$route', function ($scope, $route) {
}]);
<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" type="text/css">
</head>
<body>
<!-- Fixed navbar -->
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">Angular</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Home</a></li>
<li><a href="#/second">Second</a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div ng-view class="jumbotron"></div>
</div> <!-- /container -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.3/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.3/angular-route.js"></script>
<script src="app.js"></script>
</body>
</html>
,併爲他工作,但對我來說,只是首頁鏈接工作,而第二個鏈接不工作,直到我改變<a href="#/second">Second</a>
爲<a href="#!/second">Second</a>
它工作,但我不明白爲什麼?
它是因爲您使用的版本。您觀看的視頻可能採用角度1.4或1.5。不要去ngRoute,嘗試比ngRoute靈活的UI路由器 –
是的我的一個朋友也告訴過它! 謝謝 – damer