I have data returning from a service, but im unable to make use of that data in my controller. Please tell me what is wrong; the first console.log prints the data, but the second console.log prints null; is it because of scope issues?
var myApp = angular.module('myApp',[]);
myApp.service('dataService', function($http) {
getData = function() {
return $http({
method: 'GET',
url: 'https://www.example.com/api/v1/page',
params: 'limit=10',
headers: {}
});
} });
myApp.controller('AngularJSCtrl', function($scope, dataService) {
$scope.data = null;
dataService.getData().then(function(dataResponse) {
$scope.data = dataResponse;
console.log($scope.data); //Prints my data here//
});
console.log($scope.data); //prints null//
});