title: RangeError: Maximum call stack size exceeded (AngularJS)
body: <p>I am trying to develop a web application using AngularJS. I am not able to route the web pages using ngRoute. I have written web server in Bottle python framework, which throws no error on this part. The browser console shows this straneg error which I am not able to debug saying "RangeError: Maximum Call Stack Size Exceeded". Following are the code snippets and console stack trace.</p>
  
  <p>app.js</p>
  
  <pre><code>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 &amp;&amp; !$cookieStore.get(AUTH_EVENTS)){    
              //console.log($rootScope.AUTH_EVENTS);
              $location.path('/');
              //$route.reload();
          }
          if(absNewUrl.$$route.originalPath == '/dashboard' &amp;&amp; $rootScope.flag == false){
              $rootScope.flag = true;
          }
              //here you can check for your own condition and if not logged in then set $location.path(loginpath);
        });
  });
  </code></pre>
  
  <p>route.js</p>
  
  <pre><code>app.config(function($routeProvider) {
      $routeProvider
          .when('/', {
              templateUrl : '/assets/app/partials/login.html',
              controller : 'loginCtrl'
          })         
          .when('/dashboard', {
              templateUrl : '/assets/app/partials/main.html'
          })
          .otherwise({
              redirectTo: '/'
          });
  });
  </code></pre>
  
  <p>loginCtrl.js</p>
  
  <pre><code>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);
      }
  }])
  </code></pre>
  
  <p>loginFactory.js</p>
  
  <pre><code>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;
  }])
  </code></pre>
  
  <p>console.output and errors:</p>
  
  <pre><code>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) &lt;div ng-view="" class="ng-scope"&gt;(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 &lt;error&gt;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 &lt;error&gt;
  </code></pre>