I am currently new to AngularJS and starting to learn it.
Recently, I developed a basic app for displaying content from a JSON file. However, when attempting to access the data assigned to scope outside of the $http function, it returns as undefined.
var app = angular.module('app',[]);
app.controller('apCtrl',['$scope','$http',function($scope,$http){
$http.get('/path/to/data.json').success(function(){
console.log(data); // Data successfully returned
$scope.data = data; // Data assigned to scope
console.log($scope.data); // Data accessible
});
console.log($scope.data); // Returns 'undefined'
}]);
I would appreciate any guidance in understanding this issue.
Thank you!