Answer the question
In order to leave comments, you need to log in
How to rewrite defer in Angular 2?
There are 2 functions like this:
function func1(bla) {
var deferred;
if (condition) {
bla.forEach(function (val) {
deferred = $q.all(func2(val));
})
} else {
deferred = func2(bla);
}
return deferred;
}
function func2(bla) {
var defer = $q.defer();
if (cond2) {
defer.resolve(...);
} else {
defer.reject(...);
}
return defer.promise;
}
Answer the question
In order to leave comments, you need to log in
By using Promise directly. You should get something like this:
function func1(bla: any | any[]): Promise<any> {
if (bla instanceof Array) {
return Promise.all(bla.map(func2));
}
return func2(bla);
}
function func2(bla: any): Promise<any> {
return new Promise((resolve, reject) => {
if (cond2) {
resolve(...);
} else {
reject(...);
}
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question