我试图在Angular ui-router的父状态中执行一些初始化代码.初始化代码是orderService.getStoreInfo(),它返回一个promise.只有当这个承诺得到解决时,我才能触发子状态.但是,我注意到,即使在父母的承诺解决之前,孩子的状态也会被触发.我究竟做错了什么?这是’我的代码:
原文链接:https://www.f2er.com/angularjs/140330.htmlfunction 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',}); }
控制台日志如下:
home: resolve - orderService.getStoreInfo() home.orders: resolve - orderService.getOrders() ... messages from orderService.getStoreInfo() ...
这清楚地表明,即使在父州解决之前,子州仍在解雇.