I am sure this is an easy answer but I am not finding it anywhere. Essentially I have a $http
service that brings back a JSON object with a ton of data that I need to use like so:
(function (angular) {
angular.module("forecasting").factory("DataServices", ["$http", function ($http) {
return {
//get forecast of entity
getForecast: function (callback) {
$http({
method: "GET",
url: Forecasting.urls.entityAPIRoot + "forecast/1722"
}).success(function (data, status, headers, config) {
callback(data);
}).error(function (data, status, headers, config) {
callback(data);
});
}
}
});
} (angular));
This is just a service that takes a call back so the data can be saved to the scope like so:
DataServices.getForecast(function (data) {
$scope.forecast = data;
});
This works well when trying to show the data in the view, it updates like you think it would. However simply trying console.log($scope.forecast)
placed after the above code in my controller does not work.
I want to be able to take subsections of the data so I can use it in my app, however, I can't access $scope.forecast
so I am not sure how I am able to.
I have looked at other solutions that use $scope.$apply()
and promises. I am just kind of lost and not sure where to go from here.
How do I access a subset of the data being saved to the $scope
outside of the callback?
console.log($scope.forecast)
exactly? are you doing it after thegetForecast()
function or within it's body? – Kia Panahi Jan 14 at 21:55