angular-ui / ui-router

The de-facto solution to flexible routing with nested views in AngularJS
http://ui-router.github.io/
MIT License
13.54k stars 3k forks source link

Maximum call stack size exceeded when using new optional parameters #1098

Closed baubie closed 9 years ago

baubie commented 10 years ago

Using master pulled on May 25th, 2014, I wanted to use the new optional parameters feature of routes, so I created a route and when I load the page fresh, it works fine, but if I transition to it by clicking on a link on my site, I get a maximum call stack size exceeded.

Everything works fine if I simply remove the {first_reservable_create} optional parameter below.

Here's where I define my route:

.state('admin.manage.createreservables',{
   url:'/create/reservables/{first_reservable_create}',
   data: {
    access:{
        login_required:true,
        moderates_sites:true,
    }
   },
   templateUrl: JS_PATH.modules + '/admin/reservables/create_tpl.html',
   controller: 'adminCreateReservableCtrl',
   resolve:{
    reservableClasses:['qrse','$stateParams',function(qrse,$stateParams){
        return qrse.classes($stateParams.siteid)
    }]
   }
})

The call stack size exceeded error happens in the code below (this is from a standard grunt build of ui.router):

     // Resolve template and dependencies for all views.  This is line 2890
      forEach(state.views, function (view, name) {
        var injectables = (view.resolve && view.resolve !== state.resolve ? view.resolve : {});
        injectables.$template = [ function () {
          return $view.load(name, { view: view, locals: locals, params: $stateParams }) || '';
        }];

        // EXCEPTION THROWN BY NEXT LINE
        promises.push($resolve.resolve(injectables, locals, dst.resolve, state).then(function (result) {
          // References to the controller (only instantiated at link time)
          if (isFunction(view.controllerProvider) || isArray(view.controllerProvider)) {
            var injectLocals = angular.extend({}, injectables, locals);
            result.$$controller = $injector.invoke(view.controllerProvider, null, injectLocals);
          } else {
            result.$$controller = view.controller;
          }
          // Provide access to the state itself for internal use
          result.$$state = state;
          result.$$controllerAs = view.controllerAs;
          dst[name] = result;
        }));
      });
charandas commented 10 years ago

+1

This is happening with a Jun 2nd dev version as well. In my case, I have two states app.listing and app.listing.feature. With the release version, it has no issues changing the state using $state.go to load the child state feature in the app.listing controller.

With the master branch, my app gets into a loop trying to load app.listing within app.listing as revealed by a debug session in $state.transitionTo function, until the call stack grows far beyond.

Using the $location service to access the app.feature works for me.

charandas commented 10 years ago

@nateabele doesn't this require a little more angular-ui love? Seems pretty critical for those of us who are trying out the edge version, tempted by all the new features ;)

charandas commented 10 years ago

This has turned out to be a non-issue in my case. It was happening in a state-hierarchy where there are a default substate with empty url. By removing that state, my app behaves fine and $state.go no longer poses any issues.

eddiemonge commented 9 years ago

Can you post a plnkr example please?

eddiemonge commented 9 years ago

Actually closing this: https://gist.github.com/eddiemonge/f6a58169c2846731a1eb