Answer the question
In order to leave comments, you need to log in
What am I doing wrong with promise in AngularJS service?
Hello. Moved the data loading logic from the controller to a separate service. in the controller I call vm.projects= reportsService.initReport( vm.id);
In the initReport method itself, the following code
function initReport(id) {
getTimeTypes(isView).then(function(data){
types = data;
})
console.log(types);
return [
types
]
}
function getTimeTypes(isView){
return restAPI.getTimeTypes()
.then(
function( data ) {
var temp = [];
temp = parseResponse(data,isView);
if(temp.items && temp.items.length){
return temp.items;
}
}
)
}
getTimeTypes(isView).then(function(data){
types = data;
})
Answer the question
In order to leave comments, you need to log in
Please tell me why this code fragment is ignored, despite the presence of an asynchronous operation waiting block in it, and why the function returns the result before one of the commands is executed.
function initReport(id) {
getTimeTypes(isView).then(function(data){
return [data];
});
}
initReport(42).then(function (types) {
console.log(types);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question