Is there a way to select the current scope in ng-repeat?
I have Angular 1.x MVC as such:
...
.controller('orderdetailCtrl', ['$scope', 'orderServer', ..., function($scope, orderServer, ...) {
$scope.refundDetail = function(item) {
orderServer.refundDetailDialog(item).result.then(function(data) {
if(data) {
item.refund_info.refund_balance = data;
}
});
}
$scope.refundEdit = function(item) {
orderServer.refundEditDialog(item).result.then(function(data) {
if (data) item.refund_info.refund_balance = data;
});
}
...
}]).controller('refundDetailDialogCtrl', ['$scope', 'orderServer', ..., function($scope, orderServer, ...) {
...
$scope.cancel = function() {
$modalInstance.close($scope.entity.refund_info.refund_balance);
};
}]).factory('orderServer', [..., function(...) {
return {
refundDetailDialog: function(item) {
return $dialogs.create('/.../xxx.modal.html', 'refundDetailDialogCtrl', item, {
size: "lg"
});
},
refundEditDialog: function(item){
return $dialogs.create('/.../xxx.modal.html', 'refundEditCtrl', item);
}
...
}
}]);
Now the parent page has this setting:
<tr ng-repeat="details in entity.refundlist">
...
</tr>
There are duplicate "details" item
in $scope.refundDetail
, now the code above works just fine. Out of curiosity, I like to know if I can replace the item in the orderServer with the current amount of "parts" (which means replace item.refund_info.refund_balance = data
).
I have tried so far:
$scope.refund_info.refund_balance = data;
this.refund_info.refund_balance = data;
refund_info.refund_balance = data;
$scope.details.refund_info.refund_balance = data;
this.details.refund_info.refund_balance = data;
details.refund_info.refund_balance = data;
None of them worked.
There is a logical error in this question. When data is passed back to orderdetailCtrl
through your factory orderServer
, it is in scope orderdetailCtrl
instead of "ng-repeat scope", which means you cannot directly select "details". The current method is the only way to select "parts".