Using the ngRoute 'resolve' parameter with an injected promise

后端 未结 1 475
礼貌的吻别
礼貌的吻别 2021-02-10 17:39

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. Curre

相关标签:
1条回答
  • 2021-02-10 18:00

    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;
        };
    }])
    
    0 讨论(0)
提交回复
热议问题