Problem Question : I am making call to API and it returns the object back. Now I want to add the empty array to this object and use it in my view. How would i achieve this with angular?
// Controller This works as the data was manually
$scope.deliveryData = [
{
productName: 'ProductA ProductA ProductA', quantity: '20', deliveries: []
},
{
productName: 'Product B', quantity: '10', deliveries: []
}
];
// controller This does not work :( how would I add (deliveries:[]) to this ?
$scope.deliveryData; // This will be now populated from API
MyService.delivery()
.success(function(data){
$scope.deliveryData= data;
console.log(data) //this data does not contain the empty array, how i append to it?
})
.error(function(status,data){
console.log(status);
console.log(data);
})
I don't know how to achieve this in angular, even I don't know if I am doing this right way. Please give me any suggestions.
UPDATE 1
.success(function(data){
$scope.deliveryData = data;
console.log("Before Change");
console.log($scope.deliveryData);
for (var i = 0; i < $scope.deliveryData.length; i++) {
$scope.deliveryData[i].deliveries = [];
}
console.log("After Change");
console.log($scope.deliveryData);
})
Data coming from API in following format:
-Object {delivery: Array[1]}
--delivery: Array[1]
---0:Object
----name: "ProductA ProductA ProductA"
----quantity: 14
cart
the same asdeliveryData
above?