Struggling to pass data back to my controller from my service without success. The service works as I can see the response in console log, but not in the controller.
Service:
(function () {
angular
.module('app')
.service('testService', testService);
testService.$inject = ['$http'];
function testService($http, url) {
var baseUrl = "http://getjsondata.com/" + url;
this.getData = function (url) {
$http({
method: 'GET',
url: baseUrl + url,
headers: {'Content-Type': 'application/json'}
})
.then(function (response) {
console.log(response); // THIS WORKS
return response;
})
.catch(function (error) {
return error;
});
};
}
}());
Controller:
vm.getTestData = function (url) {
vm.response = testService.getData(url);
console.log(vm.response);
};
Attempted callbacks and factories, but still unable to access data in controller. Different ways of defining functions also tried. Return statement in service may be the issue. Seeking assistance!