Angularjs ui-router abstract state with resolve

前端 未结 1 1849
执念已碎
执念已碎 2020-11-30 13:43

Is it possible to make an abstract state with ui-router that needs to resolve data? I need to load the top half of a page with profile info, and then have a sub-nav that loa

相关标签:
1条回答
  • 2020-11-30 14:35

    Solution here is to distinguish the names of the resolved data. Check this answer:

    • angular ui-route state parent and resolve (nested resolves)

    And its plunker

    So in our case we would need this change in parent

    resolve: {
        dataParent: ['$stateParams', 'ProfileService', function ($stateParams, ProfileService) {
            var username = $stateParams.username;
            return ProfileService.getProfile(username);
        }]
    }
    

    and this in child

    resolve: {
        dataChild: ['$stateParams', 'ProfileService', function ($stateParams, ProfileService) {
            var username = $stateParams.username;
            return ProfileService.getProfileSomething(username);
        }]
    }
    

    so, instead of working with resolve : { data: ... } in parent and child we would have these:

    // parent state
    resolve : { dataParent: ... } 
    // child state
    resolve : { dataChild: ... } 
    

    One working example should be better than other words...

    0 讨论(0)
提交回复
热议问题