Here is my service code:
'use strict';
app
.service('myService', function($http) {
this.getJSON = function() {
return $http.get('someUrl/dataForm').then(function(data){
return data.result;
});
};
});
In the controller, I am using the service as follows:
'use strict'
app.controller('myController', function ($scope, myService) {
myService.getJSON().then(function(data){
$scope.myData =data;
});
console.log($scope.myData);
});
Although the http call returns a JSON value successfully, the console log displays 'undefined' for the value of myData. Can anyone help me figure out what mistake I might be making?