Skip to content Skip to sidebar Skip to footer

Using The NgRoute 'resolve' Parameter With An Injected Promise

I have configured the resolve parameter of several routes to return a promise in order to delay instantiation of the controller until the promise is resolved. Currently I am using

Solution 1:

The first example you have is the way to go, I think you could go a little bit "DRYer" like this:

.when('/article/:id', {
    ...
    resolve: {
        article: ['contentPromise', function (contentPromise) {
            return contentPromise();
        }]
    }
})

Service:

.factory('contentPromise', ['Content', '$route', function (Content, $route) {
    return function() {
        return Content.get({ contentId: $route.current.params.id }).$promise;
    };
}])

Post a Comment for "Using The NgRoute 'resolve' Parameter With An Injected Promise"