Seeking to comprehend the rationale behind it, I will share some general code snippets:
1) Fetching data from a JSON file using the "loadData" service:
return {
myData: function(){
return $http.get(path + "data.json");
}
}
2) Within the main controller:
loadData.myData().then(function(result){
$scope.vm.myData = result.data;
});
Then, whenever I try to access it with:
console.log($scope.vm)
I can see the entire object containing the data, but if I try:
console.log($scope.vm.myData)
It always returns as "undefined", and cannot be utilized in any function (except by accessing it within the above-mentioned function). My goal is to fetch some data initially and then make it accessible wherever needed.