Answer the question
In order to leave comments, you need to log in
How to return a result from a promise?
Hello!
There is an Angular service
taskApp.service('taskService', ['$http',
function ($http) {
this.getTaskList = function () {
$http.get("tasks.json").then(function (response) {
return response.data; //приходит undefined в контроллер, НИПАНЯТНА :)
}).catch(function (error) {
console.log(error.status);
});
};
}
]);
Answer the question
In order to leave comments, you need to log in
Well, you are in the place where you call this method, process the promise:
service.getTasksList().then( function(data) { controller.tasks = data; });
return $http.get("tasks.json").then(function(response){
return response.data;
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question