Ui-routes resolve isn't called

Hi,

I’m trying create a seed project using RequireJS and lazy load of modules, but the resolve method of ui-router isn’t called, neither inside views or on the url level.

Here one similar working seed project just for AngularJS https://github.com/jbolila/angular-requirejs-lazy-seed and the one for Ionic is here https://github.com/jbolila/ionic-requirejs-lazy-seed (tabs).

Any clue of what is happening?

Kind regards

Hey,

it would be really interesting.

I tried something like that on my own without the whole bunch of things
But i had no luck.

The interesting part of the whole git repo is this function:

     require(dependencies, function() {
        $rootScope.$apply(function() {
          $log.debug('SOLVED! ', dependencies);
          deferred.resolve();
        });
      });

      return deferred.promise;

But i think it would not work this way.
The resolve option is to loadData or something else of data and push them in the used controller.
So you need to dynamically return the controller name to the route…
The controller-option can handle a function but no promise function.

@mhartington
Maybe some guys from ionic could clearify that…

Is working now, and the project updated on github, thanks.

Hey guys, soo I’m a bit rusty on working with resolve…but thankfully others on the internet are pretty familiar with it.

Soo resolves functions are injectable, that need to be injected into a controller.


resolve: {
    propertyData: function($stateParams, $q) {
        // The gapi.client.realestate object should really be wrapped in an
        // injectable service for testability...
        var deferred = $q.defer();
        gapi.client.realestate.get($stateParams.propertyId).execute(function(r) {
            deferred.resolve(r);
        });
        return deferred.promise;
    }
}

and then the value from the resolve gets injected in the controller.

.controller('PropertyController', function($scope, propertyData) {
    $scope.property = propertyData;
});

For further reference, check the ui-router docs

1 Like