0
我有一個引導對話框,用戶可以在其中輸入運輸跟蹤號碼。 2個按鈕 - 一個取消,一個發貨。控制器與此相關。一旦成功,我希望將該訂單的狀態(以ng爲單位重複列表)更改爲「已發貨」。但它不起作用。我在這裏做錯了什麼?
控制器與對話子控制器:
function ManageOrderCtrl($scope, $http, $dialog) {
// Setup some dialog options for shipping popup
var dialogOptions = {
controller: 'ShipOrderCtrl',
templateUrl: '/partials/order/_ship.html'
};
// Shipping action - launches popup for tracking #
$scope.shipOrder = function(order){
var itemToEdit = order;
$dialog.dialog(angular.extend(dialogOptions, {
resolve: {
order: angular.copy(itemToEdit)
}
}
))
.open()
.then(function(result) {
if(result) {
angular.copy(result, itemToEdit);
}
itemToEdit = undefined;
})
};
}
// Shipping controller (injected in ship dialog)
function ShipOrderCtrl($scope, $http, order, dialog){
$scope.order = order;
// Called when they click "mark as shipped" on dialog
$scope.ship = function() {
dialog.close($scope.order);
//This works fine from here
//$scope.order.status = 'shipped';
$http.put('api/order/ship/' + $scope.order._id, {
tracking: $scope.order.tracking
})
.then(function(response) {
// This doesn't work
$scope.order.status = 'shipped';
});
};
// Cancel the dialog
$scope.close = function(){
dialog.close(undefined);
};
}
查看:
<div ng-conroller="ManageOrderCtrl">
<div ng-repeat="order in orders">
<span class="status">{{ order.status }}</span>
<a href="#" ng-click="shipOrder(order)"></a>
</div>
</div>
你能解釋一下「這不行」是什麼意思。是否調用'then'塊?或其他一些錯誤?代碼似乎是正確的! – rajkamal 2013-03-11 03:26:27
那麼它不會更新我的列表上的狀態。我有一段類似的代碼來取消一個可以工作的訂單 - 我猜想它與對話框的額外位有關,但是因爲我可以將它標記爲早些時候發佈(在那裏註釋掉),它似乎都是有效的。奇怪的 – cyberwombat 2013-03-11 03:30:40
我已更新我的帖子,更多代碼 – cyberwombat 2013-03-11 03:36:36