我在我的网站上使用这个简单的脚本,但它在控制台中抛出错误"超出最大调用堆栈大小"
var myapp = angular.module("myApp", ['ngRoute']);
myapp.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
//$locationProvider.html5mode(true);
$routeProvider
.when('/', {
templateUrl: 'index.html',
}).when('/contact',
templateUrl: 'contact.html',
}).when('/google', {
templateUrl: 'http://www.google.co.in'
}).otherwise({
redirectTo: '/'
});
}]);
Run Code Online (Sandbox Code Playgroud)
我想你误解了Angular中的路由是什么.
首先,关于你的问题,我假设你从index.html调用这个代码,因此路由将连续循环到index.html,因为"otherwise()"规则将加载将加载的'/'规则index.html无限(导致调用堆栈溢出).
其次,路由应该将部分HTML加载到ngView指令中,而不是将用户发送到不同的URL.请阅读https://docs.angularjs.org/tutorial/step_07
| 归档时间: |
|
| 查看次数: |
2877 次 |
| 最近记录: |