Hemant.kr12
Hemant.kr12

Reputation: 11

"maximum call stack size exceeded"

I am using this simple script in my website but its throwing error in console as "maximum call stack size exceeded"

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

Upvotes: 1

Views: 3060

Answers (1)

Itamar L.
Itamar L.

Reputation: 519

I think you misunderstood what routing in Angular is for.

First of all, regarding your problem, I assume you are calling this code from index.html, therefore the routing will continuously loop to index.html due to the "otherwise()" rule which will load the '/' rule which will load index.html infinitely (causing the call stack to overflow).

Secondly, routing is supposed to load partial HTML into the ngView directive and not send the user to different URLs. Please read https://docs.angularjs.org/tutorial/step_07

Upvotes: 5

Related Questions