angular.js:117 RangeError:超出最大调用堆栈大小

时间:2016-08-05 03:11:35

标签: javascript angularjs

我正在处理我的第一个angular.js,但我的应用程序出现错误,它一直在循环。我认为错误在我的ng-route配置中,但我无法弄清楚如何解决它。

myapp.js

var app = angular.module('myapp', ['ngRoute']);

 app.config(function($routeProvider) {
            $routeProvider.

            when('/', {
              templateUrl: 'index.html',
              controller: 'mainController'

            }).

            when('/main', {
               templateUrl: 'main.html',
               controller: 'mainController'
            }).

            when('/register', {
               templateUrl: 'register.html',
               controller: 'authController'
            }).

            when('/update', {
               templateUrl: 'update.html',
               controller: 'authController'
            }).

            otherwise({
               redirectTo: '/'
            });
});


app.controller('mainController', function($scope){

});

app.controller('authController', function($scope){


  $scope.update = function(){

  };

  $scope.register = function(){

  };
});

的index.html

        <div ng-view> </div>

堆叠错误。

angular.js:117 RangeError: Maximum call stack size exceeded
        at ja (http://localhost:3000/javascripts/angular.js:80:376)
        at n (http://localhost:3000/javascripts/angular.js:66:28)
        at g (http://localhost:3000/javascripts/angular.js:58:305)
        at g (http://localhost:3000/javascripts/angular.js:58:322)
        at g (http://localhost:3000/javascripts/angular.js:58:322)
        at http://localhost:3000/javascripts/angular.js:57:455

        at http://localhost:3000/javascripts/angular-route.js:866:15
        at http://localhost:3000/javascripts/angular.js:57:445
        at http://localhost:3000/javascripts/angular.js:62:281
        at update (http://localhost:3000/javascripts/angular-route.js:839:13)(anonymous function) @ angular.js:117(anonymous function) @ angular.js:89ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820
    11angular.js:117 RangeError: Maximum call stack size exceeded
        at Object.error (http://localhost:3000/javascripts/angular.js:117:212)
        at http://localhost:3000/javascripts/angular.js:89:505
        at ja (http://localhost:3000/javascripts/angular.js:80:372)
        at n (http://localhost:3000/javascripts/angular.js:66:28)
        at g (http://localhost:3000/javascripts/angular.js:58:305)
        at g (http://localhost:3000/javascripts/angular.js:58:322)
        at g (http://localhost:3000/javascripts/angular.js:58:322)
        at http://localhost:3000/javascripts/angular.js:57:455
        at http://localhost:3000/javascripts/angular-route.js:866:15
        at http://localhost:3000/javascripts/angular.js:57:445(anonymous function) @ angular.js:117(anonymous function) @ angular.js:89ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820
    angular.js:117 RangeError: Maximum call stack size exceeded
        at Object.error (http://localhost:3000/javascripts/angular.js:117:212)
        at http://localhost:3000/javascripts/angular.js:89:505
        at ja (http://localhost:3000/javascripts/angular.js:80:372)
        at n (http://localhost:3000/javascripts/angular.js:66:28)
        at g (http://localhost:3000/javascripts/angular.js:58:305)
        at g (http://localhost:3000/javascripts/angular.js:58:322)
        at g (http://localhost:3000/javascripts/angular.js:58:322)
        at http://localhost:3000/javascripts/angular.js:57:455
        at http://localhost:3000/javascripts/angular-route.js:866:15
        at http://localhost:3000/javascripts/angular.js:57:445 <!-- ngView:  -->(anonymous function) @ angular.js:117(anonymous function) @ angular.js:89ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820ja @ angular.js:80n @ angular.js:66g @ angular.js:58g @ angular.js:58g @ angular.js:58(anonymous function) @ angular.js:57(anonymous function) @ angular-route.js:866(anonymous function) @ angular.js:57(anonymous function) @ angular.js:62update @ angular-route.js:839(anonymous function) @ angular-route.js:820
    10angular.js:117 RangeError: Maximum call stack size exceeded
        at RegExp.[Symbol.replace] (native)
        at RegExp.[Symbol.replace] (native)
        at String.replace (native)
        at cb (http://localhost:3000/javascripts/angular.js:29:523)
        at xa (http://localhost:3000/javascripts/angular.js:87:188)
        at x (http://localhost:3000/javascripts/angular.js:60:1)
        at s (http://localhost:3000/javascripts/angular.js:58:402)
        at s (http://localhost:3000/javascripts/angular.js:59:55)
        at s (http://localhost:3000/javascripts/angular.js:59:55)
        at s (http://localhost:3000/javascripts/angular.js:59:55) <!-- ngView:  -->

1 个答案:

答案 0 :(得分:2)

问题在于以下代码:

        when('/', {
          templateUrl: 'index.html',
          controller: 'mainController'

        }).

index.html<div ng-view> </div>。因此angularjs尝试用index.html替换ng-view,这就像无限递归一样继续。

您可以做的是添加home.html

 <div>Home page</div>

并将路由替换为:

    when('/', {
      templateUrl: 'home.html',
      controller: 'mainController'

    }).