我在角度应用程序中设置了几个状态,如下所示:
.state('createOrder', {
url: '/customer-services/orders/create?orderNumber',
templateUrl: 'tpl/customerServices/orders/save.html',
controller: 'SaveOrderController',
controllerAs: 'controller',
params: {
accountNumber: null,
},
resolve: {
// If we have an order number, we populate the new order
order: ['$q', '$stateParams', 'OrderService', 'SaveOrderService', function ($q, $stateParams, service, shared) {
// Get our order number
var orderNumber = $stateParams.orderNumber;
// Defer our promise
var deferred = $q.defer();
// If we have an order number
if (orderNumber) {
// Get our order from the system
service.get(orderNumber).then(function (response) {
// Loop through the current lines
for (var i = 0; i < response.lines.length; i++) {
// Get the current line
var line = response.lines[i];
// Set to disabled
line.disabled = true;
}
// Assign our models
shared.order = response;
// Resolve our promise
deferred.resolve();
});
// If we don't have an order number
} else {
// Resolve our promise anyway
deferred.resolve();
}
// Return our promise
return deferred.promise;
}],
// Updates the account number in our order
updateAccount: ['$stateParams', 'SaveOrderService', function ($stateParams, shared) {
// Assigns the account number to the parameter if it has been passed
shared.order.accountNumber = $stateParams.accountNumber;
}]
},
data: {
requireLogin: true,
pageTitle: 'Add order'
}
}).state('createOrder.lines', {
url: '/lines',
views: {
'@': {
templateUrl: 'tpl/customerServices/orders/save/lines.html',
controller: 'SaveOrderLinesController',
controllerAs: 'controller'
}
},
params: {
id: null
},
resolve: {
validate: ['$state', '$stateParams', '$timeout', 'SaveOrderService', function ($state, $stateParams, $timeout, shared) {
console.log(shared);
// If we don't have an account number
if (!shared.order.accountNumber) {
// Timeout to avoid digest issues
$timeout(function () {
// Redirect to the create order view
$state.go('createOrder', { orderNumber: $stateParams.orderNumber });
});
}
}],
// Genearates a default order line for selects an existing one for editing
orderLine: ['$stateParams', 'ArrayService', 'SaveOrderService', function ($stateParams, arrayService, shared) {
// Get our id
var id = $stateParams.id;
// If we have an id
if (id) {
// Get our index
var index = arrayService.indexOf(shared.order.lines, { id: id }, 'id');
// If our index is greater than -1
if (index > -1) {
// Return the current line
return shared.order.lines[index];
}
}
// Falback, return blank (ish) order line
return {
forDelivery: true,
quantity: 1,
unitOfMeasure: 0
};
}],
// If we have an existing line, gets the product
product: ['ProductService', 'SaveOrderService', 'orderLine', function (service, shared, orderLine) {
// If we have a product
if (orderLine.productCode) {
// Return our product
return service.get(orderLine.productCode, shared.order.accountNumber);
}
// Fallback, return nothing
return null;
}]
},
data: {
requireLogin: true,
pageTitle: 'Add order : Lines'
}
})
我想要的是我的&#34; 订单&#34;解决在子状态( createOrder.lines )上调用任何结算之前要解决的问题。我认为使用promise会做到这一点,但如果我在提供 orderNumber 时直接进入行视图,我的验证会失败。
有人知道如何在行状态验证之前获得解决的订单吗?
答案 0 :(得分:0)
这是我在ui-router文档中找到的继承已解析依赖项...
如果您愿意,必须将解析密钥注入子状态 在实例化之前等待promises得到解决 孩子。