I'm trying to expose the data obtained from the success method of a promise. In short, I don't know how to grab $scope.storedData
. As it is right now, it is undefined.
genericService.js
myApp.factory('genericService', function($http){
return $http.jsonp('http://foo.com/bar.json')
.success(function(data){
return data;
})
.error(function(err){
return err;
});
});
genericController.js
myApp.controller('genericController', ['$scope','genericService',
function($scope, genericService){
genericService.success(function(data){
$scope.storeData(data);
});
$scope.storedData; // Undefined here.
$scope.storeData = function(whatever){
$scope.storedData = whatever;
}
console.log('data stored is: ', $scope.storedData); // Still undefined
}]);
How do I expose $scope.storedData
to the scope outside of storeData()
or genericService.success()
?
Note: I don't want to use $watch
. I want to overcome this scope issue fairly un-Angularly... because it should be possible.