angularjs - ui-router triggers child state before parent state is resolved -
i trying execute initialization code in parent state of angular ui-router. initialization code orderservice.getstoreinfo()
returns promise. when promise resolved, want trigger child state. however, noticing child state triggered before parent's promise has resolved. doing wrong? here' code:
function configure($stateprovider, $urlrouterprovider) { $urlrouterprovider.otherwise('/'); $stateprovider .state('home', { abstract: true, template: '<ui-view/>', resolve: { storeinfo: /* @nginject */ function(orderservice) { console.log('home: resolve - orderservice.getstoreinfo()'); return orderservice.getstoreinfo(); } } }) .state('home.orders', { url: '^/', template: '<my-order-list data-orders="vm.orders"></my-order-list>', resolve: { orders: /* @nginject */ function (orderservice) { console.log('home.orders: resolve - orderservice.getorders()'); return orderservice.getorders(); } }, controller: ['orders', function (orders) { this.orders = orders; }], controlleras: 'vm', }); }
the console log follows:
home: resolve - orderservice.getstoreinfo() home.orders: resolve - orderservice.getorders() ... messages orderservice.getstoreinfo() ...
this shows child state firing before parent state has been resolved.
the answer here: resolve
keys must injected child states if want wait promises resolved before instantiating children. explicitly inject storeinfo
resolve function of child state.