RangeError:超出最大调用堆栈大小(AngularJS)

时间:2015-06-18 05:27:42

标签: javascript python angularjs

我正在尝试使用AngularJS开发Web应用程序。我无法使用ngRoute路由网页。我在Bottle python框架中编写了Web服务器,这部分没有抛出任何错误。浏览器控制台显示此straneg错误,我无法调试说" RangeError:超出最大调用堆栈大小"。以下是代码片段和控制台堆栈跟踪。

app.js

var app = angular.module('tslApp', ['ngRoute','datatables','ngCookies']);

app.constant('AUTH_EVENTS', {
      loginSuccess: 'auth-login-success',
      loginFailed: 'auth-login-failed',
      logoutSuccess: 'auth-logout-success',
      sessionTimeout: 'auth-session-timeout',
      notAuthenticated: 'auth-not-authenticated',
      notAuthorized: 'auth-not-authorized'
})

app.run(function ($rootScope,$location,AUTH_EVENTS,$cookieStore,$http,$q,$timeout) {
    $rootScope.flag = false;
    $rootScope.$on('$routeChangeStart', function(evt, absNewUrl, absOldUrl) {
        $cookieStore.get(AUTH_EVENTS);
        if($rootScope.AUTH_EVENTS != AUTH_EVENTS.loginSuccess && !$cookieStore.get(AUTH_EVENTS)){    
            //console.log($rootScope.AUTH_EVENTS);
            $location.path('/');
            //$route.reload();
        }
        if(absNewUrl.$$route.originalPath == '/dashboard' && $rootScope.flag == false){
            $rootScope.flag = true;
        }
            //here you can check for your own condition and if not logged in then set $location.path(loginpath);
      });
});

route.js

app.config(function($routeProvider) {
    $routeProvider
        .when('/', {
            templateUrl : '/assets/app/partials/login.html',
            controller : 'loginCtrl'
        })         
        .when('/dashboard', {
            templateUrl : '/assets/app/partials/main.html'
        })
        .otherwise({
            redirectTo: '/'
        });
});

loginCtrl.js

app.controller('loginCtrl', ['$scope','$rootScope', 'loginFactory', function($scope, $rootScope, loginFactory) {
    $(function() {
        $('#toggle-login').click(function() {
            $('#login').toggle();
        });
    })
    $scope.errormessage = new Object();
    $scope.successMessage = new Object();
    $scope.errormessage.isError = false;
    $scope.successMessage.isSuccess = false;
    $rootScope.AUTH_EVENTS = "auth-not-authorized";
    $scope.login = function(credentials) {
        console.log(credentials);
        loginFactory.login(credentials);
    }
}])

loginFactory.js

app.factory('loginFactory', ['$http', '$q','$rootScope','AUTH_EVENTS' ,'$location','$cookieStore', function ($http,$q,$rootScope,AUTH_EVENTS,$location,$cookieStore) {
    var loginData = {};

    loginData.login = function(credentials) {
        var $promise = $http.post('/login', credentials); //send data to server.py
        $promise.then(function(msg) {
            console.log(msg);
            if (msg.data == 'success') {
                $rootScope.AUTH_EVENTS = AUTH_EVENTS.loginSuccess;
                $cookieStore.put(AUTH_EVENTS, AUTH_EVENTS.loginSuccess);
                $location.path('/dashboard');
            } else {
                $rootScope.AUTH_EVENTS = AUTH_EVENTS.loginFailed;
                scope.errormessage.isError = true;
                scope.errormessage.msg = "Wrong username and password";
                console.log("failed 1");
            }
        }, function() {
            $rootScope.AUTH_EVENTS = AUTH_EVENTS.loginFailed;
            console.log("failed 2");
        });
    }
    return loginData;
}])

console.output和错误:

Object {username: "cdcd", password: "cdcdc"}
loginFactory.js:7 Object {data: "success", status: 200, config: Object, statusText: "OK"}
angular.js:11383 RangeError: Maximum call stack size exceeded
    at invokeLinkFn (http://localhost:7000/assets/js/angular.js:8127:30)
    at nodeLinkFn (http://localhost:7000/assets/js/angular.js:7637:11)
    at compositeLinkFn (http://localhost:7000/assets/js/angular.js:6993:13)
    at compositeLinkFn (http://localhost:7000/assets/js/angular.js:6996:13)
    at compositeLinkFn (http://localhost:7000/assets/js/angular.js:6996:13)
    at compositeLinkFn (http://localhost:7000/assets/js/angular.js:6996:13)
    at publicLinkFn (http://localhost:7000/assets/js/angular.js:6872:30)
    at link (http://localhost:7000/assets/js/angular-route.min.js:7:388)
    at invokeLinkFn (http://localhost:7000/assets/js/angular.js:8125:9)
    at nodeLinkFn (http://localhost:7000/assets/js/angular.js:7637:11) <div ng-view="" class="ng-scope">(anonymous function) @ angular.js:11383(anonymous function) @ angular.js:8459invokeLinkFn @ angular.js:8127nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664v @ angular-route.js:865link @ angular-route.js:831invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996publicLinkFn @ angular.js:6872link @ angular-route.js:915invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664v @ angular-route.js:865link @ angular-route.js:831invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996publicLinkFn @ angular.js:6872link @ angular-route.js:915invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664v @ angular-route.js:865link @ angular-route.js:831invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996publicLinkFn @ angular.js:6872link @ angular-route.js:915invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664v @ angular-route.js:865link @ angular-route.js:831invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996publicLinkFn @ angular.js:6872link @ angular-route.js:915invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664v @ angular-route.js:865link @ angular-route.js:831invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996publicLinkFn @ angular.js:6872link @ angular-route.js:915invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664v @ angular-route.js:865link @ angular-route.js:831invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996publicLinkFn @ angular.js:6872link @ angular-route.js:915invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664v @ angular-route.js:865link @ angular-route.js:831invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996publicLinkFn @ angular.js:6872link @ angular-route.js:915invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664v @ angular-route.js:865link @ angular-route.js:831invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996publicLinkFn @ angular.js:6872link @ angular-route.js:915invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664v @ angular-route.js:865link @ angular-route.js:831invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996publicLinkFn @ angular.js:6872link @ angular-route.js:915invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664v @ angular-route.js:865link @ angular-route.js:831invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996publicLinkFn @ angular.js:6872link @ angular-route.js:915invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664v @ angular-route.js:865link @ angular-route.js:831invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996publicLinkFn @ angular.js:6872link @ angular-route.js:915invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664v @ angular-route.js:865link @ angular-route.js:831invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996publicLinkFn @ angular.js:6872link @ angular-route.js:915invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664
VM101:1122 <error>InjectedScript._isHTMLAllCollection @ VM101:1122InjectedScript.isPrimitiveValue @ VM101:285InjectedScript.RemoteObject @ VM101:1251InjectedScript._wrapObject @ VM101:387InjectedScript.wrapObject @ VM101:298(anonymous function) @ angular.js:11383(anonymous function) @ angular.js:8459invokeLinkFn @ angular.js:8127nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664v @ angular-route.js:865link @ angular-route.js:831invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996publicLinkFn @ angular.js:6872link @ angular-route.js:915invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664v @ angular-route.js:865link @ angular-route.js:831invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996publicLinkFn @ angular.js:6872link @ angular-route.js:915invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664v @ angular-route.js:865link @ angular-route.js:831invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996publicLinkFn @ angular.js:6872link @ angular-route.js:915invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664v @ angular-route.js:865link @ angular-route.js:831invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996publicLinkFn @ angular.js:6872link @ angular-route.js:915invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664v @ angular-route.js:865link @ angular-route.js:831invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996publicLinkFn @ angular.js:6872link @ angular-route.js:915invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664v @ angular-route.js:865link @ angular-route.js:831invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996publicLinkFn @ angular.js:6872link @ angular-route.js:915invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664v @ angular-route.js:865link @ angular-route.js:831invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996publicLinkFn @ angular.js:6872link @ angular-route.js:915invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664v @ angular-route.js:865link @ angular-route.js:831invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996publicLinkFn @ angular.js:6872link @ angular-route.js:915invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664v @ angular-route.js:865link @ angular-route.js:831invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996publicLinkFn @ angular.js:6872link @ angular-route.js:915invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664v @ angular-route.js:865link @ angular-route.js:831invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996publicLinkFn @ angular.js:6872link @ angular-route.js:915invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664v @ angular-route.js:865link @ angular-route.js:831invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996publicLinkFn @ angular.js:6872link @ angular-route.js:915invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993publicLinkFn @ angular.js:6872boundTranscludeFn @ angular.js:7011controllersBoundTransclude @ angular.js:7664v @ angular-route.js:865link @ angular-route.js:831invokeLinkFn @ angular.js:8125nodeLinkFn @ angular.js:7637compositeLinkFn @ angular.js:6993compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996compositeLinkFn @ angular.js:6996publicLinkFn @ angular.js:6872link @ angular-route.js:915invokeLinkFn @ angular.js:8125
5VM101:1122 <error>

1 个答案:

答案 0 :(得分:3)

当在以下代码

中创建路由循环时,通常会发生此错误
List<double> distance = new List<double>();
List<double> speed = new List<double>();

// distance and speed are populated using Add()

List<double> slope = new List<double>();
double rise, run;
for (int i= 0; i< distance.Count(); i++)
{
    rise = 0.0;
    run = 0.0;
    if (i> 0)
    {
        rise = speed[i] - speed[i- 1];
        run = distance[i] - distance[i- 1];

        if (rise == 0 || run == 0)
        {
            slope.Add(0.0);
        }
        else slope.Add(rise/run);

    }
    else slope.Add(0.0);
    Console.WriteLine("{0}, {1}, {2}, {3}, {4}", i, rise, run, rise/run, slope);
}

您可能正在重定向到loginfactory的路由,并且由于某些情况,它会在$ routeChangeStart事件中一次又一次地被处理