2

Im working on my first angular.js but my application got an error it keeps on looping. I think the error is in my ng-route configuration but i cant figure it how to solve it.

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>

Stack Error.

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 Answer 1

3

The issue is with the following code:

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

        }).

And the index.html has <div ng-view> </div>. So the angularjs tries to replace ng-view with index.html and this goes on and on like a infinite recursion.

What you can do is add home.html

 <div>Home page</div>

and replace the routing as:

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

    }).
Sign up to request clarification or add additional context in comments.

2 Comments

I replace the index.html but when i click to another link i got this error 404 not found
Don't replace index.html. You need bothe index.html & home.html. index.html is your main file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.