Encountering the following error
angular.js:13550 TypeError: Cannot read property 'get' of undefined at Object.DataService.getDataFromAPI
I seem to be struggling with the $HTTP.get function. Any insights on what might be going wrong or how to resolve it? I suspect the issue lies in passing the $HTTP into the nested function.
(function (module) { 'use strict';
DataService.$inject = ['$http', '$q'];
function DataService($http, $q) {
var getDataFromAPI = function ($http) {
$http.get("http://localhost:34183/myAPI")
.then(function (response) {
console.log(response);
console.log(response.data);
return response.data;
});
};
}
return {
getDataFromAPI: getDataFromAPI
};
}
module.factory('DataService', DataService);
})(angular.module('ClassAPP'));
Showcasing that the method works when directly embedding the JSON data.
DataService.$inject = ['$http', '$q'];
function DataService($http, $q) {
var getDataFromAPI = function ($http) {
return [{
"Grade": "A+",
"Class": {
"Subject": "Select Topics in Basket Weaving",
"Professor": "DJ Khaled"
}
}];
};
return {
getDataFromAPI: getDataFromAPI
};
}
module.factory('DataService', DataService);
})(angular.module('ClassAPP'));