Spending too much time on a development issue is causing me frustration. After extensive research, I find myself stuck at this point.
The problem lies in making a GET request from a service which is called by a controller.
Below is the code for the service responsible for the GET request, ajaxSrvc.js
:
app.service('ajaxSrvc', ['$log', 'Constants', '$http', '$q',
function($log, Constants, $http, $q) {
this.getAllTasks = function() {
var defer = $q.defer();
var url = 'http://localhost:9998/tasks';
$http.get(url, {cache: 'true'})
.success(function(data) {
defer.resolve(data);
});
return defer.promise;
};
}
]);
This GET request is triggered by the following controller, tasksCtrl.js
:
app.controller('tasksCtrl', ["$log", "$scope", "Constants","$location", "ajaxSrvc",
function($log, $scope, Constants, $location, ajaxSrvc) {
var someData = null;
ajaxSrvc.getAllTasks().then(function(data) {
console.log(data);
someData = data;
});
console.log(someData); // Outputting NULL
}
]);
Despite my efforts, when trying to display someData
, it only shows as NULL
instead of the expected information from the GET
request.
I am seeking guidance on resolving this issue. Any suggestions?