嘗試複製簡單路由示例w3schools,但在訪問index.html時,它在控制檯中始終與「RangeError:Maximum call stack size exceeded」一起崩潰。ng-view導致頁面崩潰
我試圖添加/刪除部分代碼來隔離問題,並且崩潰似乎發生在<div ng-view></div>
。這是爲什麼?我從原來的例子中做出的改變並不那麼激烈。
下面是代碼
的index.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-route.js"></script>
<script src="app.js"></script>
</head>
<body ng-app="myApp">
<a href="#!red">Red</a>
<a href="#!green">Green</a>
<div ng-view></div>
</body>
</html>
app.js
var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider) {
$routeProvider
.when("/", {
templateUrl : "index.html"
})
.when("/red", {
templateUrl : "red.html"
})
.when("/green", {
templateUrl : "green.html"
});
});
red.html
This is red
green.html
This is green