I cannot wrap my brain around the concept of asynchronous requests.
I have a controller for my view that instantiates an object from the provider:
va.controller('VaCtrl',function($scope,$shipment){ $scope.shipment = $shipment.Shipment(); });
The supplier:
Shipment.provider('$shipment',function(){ this.$get = function($http){ function Shipment(){ } Shipment.prototype.fetchShipment = function(){ var shipment = undefined; $http.post('../sys/core/fetchShipment.php',{
My goal is to access data from Shipment.prototype.fetchShipment() inside my controller. My approach:
$scope.fetchShipment = function(){ var shipment = $scope.shipment.fetchShipment(); console.log(shipment);
However, this will return undefined.
I read about $ q and canceled promises and callbacks, and now I look like WTF; all i want to do is push the received data to my controller, what is the best way to do this?
source share