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) {
            returncontentPromise();
        }]
    }
})

Service:

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

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