I don't understand how to wait for the resource call to finish before assigning the data.properties to $scope in my controller.
here is my confusion:
i have a resource call that returns this:
[
{
"PreAlertInventory": "5.000000",
"SharesInInventory": "3.000000",
"TotalSharesSold": "2.000000",
"TotalMoneySharesSold": "18.000000",
"TotalSharesBought": "0.000000",
"TotalShareCost": "0.000000",
"EstimatedLosses": "0.000000"
}
]
here is the applicable code from the controller:
$scope.alertSwap = function () {
var data = Data.query(); // gets the data. works as expected
//$scope.test = data; //works as expected. can access data and properties in template
$scope.test = data.TotalMoneySharesSold; //does not work. is empty???
}
i can access the array and its properties from the template BUT not from inside the controller.
How do I access the child elements from inside the controller that called the resource?
http://plnkr.co/edit/JnLqq4v7lKlYOHg85Jma?p=preview
answer: thanks to all who helped:
I needed to assign a callback to the resource call, and assign the elements from within the function:
$scope.data = Data.query(myParams, function(data) {
$scope.test = data[0].TotalSharesBought;
});
$scope.testTwo = data[0].TotalSharesBought