【问题标题】:"maximum call stack size exceeded"“超出最大调用堆栈大小”
【发布时间】:2015-10-24 06:59:02
【问题描述】:

我在我的网站中使用这个简单的脚本,但它在控制台中抛出错误为“超出最大调用堆栈大小”

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: '/'
    });
}]);

【问题讨论】:

  • 修复语法错误和无效的跨域url

标签: angularjs routing


【解决方案1】:

我想你误解了 Angular 中路由的用途。

首先,关于您的问题,我假设您是从 index.html 调用此代码,因此由于“otherwise()”规则将加载“/”规则,因此路由将不断循环到 index.html这将无限加载 index.html(导致调用堆栈溢出)。

其次,路由应该将部分 HTML 加载到 ngView 指令中,而不是将用户发送到不同的 URL。请阅读https://docs.angularjs.org/tutorial/step_07

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-29
    • 2017-12-27
    • 2020-12-06
    • 2018-02-06
    • 2020-06-28
    • 2016-02-28
    • 2019-05-21
    • 2019-05-29
    相关资源
    最近更新 更多