Angular Promise.all in timeout event not working
I have the following issue using Angular 6. What I'm trying to do is to wait some promises to be resolved in order to do something else. Here is what I have and it's working:
AppService.ts
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class AppService {
p1: Promise<any>;
p2: Promise<any>;
constructor() {
this.getPromise1();
this.getPromise2();
}
getPromise1() {
this.p1 = new Promise((resolve, reject) => {
resolve(true);
});
}
getPromise2() {
this.p2 = new Promise((resolve, reject) => {
setTimeout(() => resolve(true), 5000);
});
}
}
AppComponent.ts
import { Component, AfterViewInit } from '@angular/core';
import { AppService } from './app.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements AfterViewInit {
constructor(private appSrvc: AppService) { }
ngAfterViewInit(){
Promise.all([this.appSrvc.p1, this.appSrvc.p2])
.then(values => {
console.log(values);
//If all promises resolved then execute something here
})
.catch(error => {
console.log(error.message)
});
}
}
Now when I edit the following it's not working:
AppService.ts
constructor() {
this.initialize();
}
initialize(){
setTimeout(() => {
this.getPromise1();
this.getPromise2();
}, 1000);
}
...
When I call the same promises from another method with a timeout event they don't work and I can't understand why. Can anyone help me with this.
Thanks in advance
javascript
|
show 1 more comment
I have the following issue using Angular 6. What I'm trying to do is to wait some promises to be resolved in order to do something else. Here is what I have and it's working:
AppService.ts
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class AppService {
p1: Promise<any>;
p2: Promise<any>;
constructor() {
this.getPromise1();
this.getPromise2();
}
getPromise1() {
this.p1 = new Promise((resolve, reject) => {
resolve(true);
});
}
getPromise2() {
this.p2 = new Promise((resolve, reject) => {
setTimeout(() => resolve(true), 5000);
});
}
}
AppComponent.ts
import { Component, AfterViewInit } from '@angular/core';
import { AppService } from './app.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements AfterViewInit {
constructor(private appSrvc: AppService) { }
ngAfterViewInit(){
Promise.all([this.appSrvc.p1, this.appSrvc.p2])
.then(values => {
console.log(values);
//If all promises resolved then execute something here
})
.catch(error => {
console.log(error.message)
});
}
}
Now when I edit the following it's not working:
AppService.ts
constructor() {
this.initialize();
}
initialize(){
setTimeout(() => {
this.getPromise1();
this.getPromise2();
}, 1000);
}
...
When I call the same promises from another method with a timeout event they don't work and I can't understand why. Can anyone help me with this.
Thanks in advance
javascript
1
Well, code fromngAfterViewInitis executed right away (at least, most likely within a second), while your service's promises become initialized only after a second (setTimeoutbeing async). Therefore, whenPromise.all([this.appSrvc.p1, this.appSrvc.p2])is executed, said promises are still null. What exactly are you trying to accomplish / what is the purpose ofsetTimeouthere?
– Jeto
Nov 26 '18 at 7:58
Ok I understand but how can I resolve this problem? Where do I need to have the Promise.all in my component in order to wait the promises until they resolved
– Bad_Pan
Nov 26 '18 at 8:02
You didn't answer that question at the end of my comment: what are you trying to accomplish?Promise.allalready does what you need, it waits until promises are resolved before doing something else.
– Jeto
Nov 26 '18 at 8:03
I think you should switch to observable. Promise is concept that has fundamentally one application making ajax request. It was not design to do anything else.
– piotr szybicki
Nov 26 '18 at 8:11
setTimeout is just to emulate the time that is spent for data retrieval from other services and different calculations
– Bad_Pan
Nov 26 '18 at 8:14
|
show 1 more comment
I have the following issue using Angular 6. What I'm trying to do is to wait some promises to be resolved in order to do something else. Here is what I have and it's working:
AppService.ts
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class AppService {
p1: Promise<any>;
p2: Promise<any>;
constructor() {
this.getPromise1();
this.getPromise2();
}
getPromise1() {
this.p1 = new Promise((resolve, reject) => {
resolve(true);
});
}
getPromise2() {
this.p2 = new Promise((resolve, reject) => {
setTimeout(() => resolve(true), 5000);
});
}
}
AppComponent.ts
import { Component, AfterViewInit } from '@angular/core';
import { AppService } from './app.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements AfterViewInit {
constructor(private appSrvc: AppService) { }
ngAfterViewInit(){
Promise.all([this.appSrvc.p1, this.appSrvc.p2])
.then(values => {
console.log(values);
//If all promises resolved then execute something here
})
.catch(error => {
console.log(error.message)
});
}
}
Now when I edit the following it's not working:
AppService.ts
constructor() {
this.initialize();
}
initialize(){
setTimeout(() => {
this.getPromise1();
this.getPromise2();
}, 1000);
}
...
When I call the same promises from another method with a timeout event they don't work and I can't understand why. Can anyone help me with this.
Thanks in advance
javascript
I have the following issue using Angular 6. What I'm trying to do is to wait some promises to be resolved in order to do something else. Here is what I have and it's working:
AppService.ts
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class AppService {
p1: Promise<any>;
p2: Promise<any>;
constructor() {
this.getPromise1();
this.getPromise2();
}
getPromise1() {
this.p1 = new Promise((resolve, reject) => {
resolve(true);
});
}
getPromise2() {
this.p2 = new Promise((resolve, reject) => {
setTimeout(() => resolve(true), 5000);
});
}
}
AppComponent.ts
import { Component, AfterViewInit } from '@angular/core';
import { AppService } from './app.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements AfterViewInit {
constructor(private appSrvc: AppService) { }
ngAfterViewInit(){
Promise.all([this.appSrvc.p1, this.appSrvc.p2])
.then(values => {
console.log(values);
//If all promises resolved then execute something here
})
.catch(error => {
console.log(error.message)
});
}
}
Now when I edit the following it's not working:
AppService.ts
constructor() {
this.initialize();
}
initialize(){
setTimeout(() => {
this.getPromise1();
this.getPromise2();
}, 1000);
}
...
When I call the same promises from another method with a timeout event they don't work and I can't understand why. Can anyone help me with this.
Thanks in advance
javascript
javascript
asked Nov 26 '18 at 7:30
Bad_PanBad_Pan
8611
8611
1
Well, code fromngAfterViewInitis executed right away (at least, most likely within a second), while your service's promises become initialized only after a second (setTimeoutbeing async). Therefore, whenPromise.all([this.appSrvc.p1, this.appSrvc.p2])is executed, said promises are still null. What exactly are you trying to accomplish / what is the purpose ofsetTimeouthere?
– Jeto
Nov 26 '18 at 7:58
Ok I understand but how can I resolve this problem? Where do I need to have the Promise.all in my component in order to wait the promises until they resolved
– Bad_Pan
Nov 26 '18 at 8:02
You didn't answer that question at the end of my comment: what are you trying to accomplish?Promise.allalready does what you need, it waits until promises are resolved before doing something else.
– Jeto
Nov 26 '18 at 8:03
I think you should switch to observable. Promise is concept that has fundamentally one application making ajax request. It was not design to do anything else.
– piotr szybicki
Nov 26 '18 at 8:11
setTimeout is just to emulate the time that is spent for data retrieval from other services and different calculations
– Bad_Pan
Nov 26 '18 at 8:14
|
show 1 more comment
1
Well, code fromngAfterViewInitis executed right away (at least, most likely within a second), while your service's promises become initialized only after a second (setTimeoutbeing async). Therefore, whenPromise.all([this.appSrvc.p1, this.appSrvc.p2])is executed, said promises are still null. What exactly are you trying to accomplish / what is the purpose ofsetTimeouthere?
– Jeto
Nov 26 '18 at 7:58
Ok I understand but how can I resolve this problem? Where do I need to have the Promise.all in my component in order to wait the promises until they resolved
– Bad_Pan
Nov 26 '18 at 8:02
You didn't answer that question at the end of my comment: what are you trying to accomplish?Promise.allalready does what you need, it waits until promises are resolved before doing something else.
– Jeto
Nov 26 '18 at 8:03
I think you should switch to observable. Promise is concept that has fundamentally one application making ajax request. It was not design to do anything else.
– piotr szybicki
Nov 26 '18 at 8:11
setTimeout is just to emulate the time that is spent for data retrieval from other services and different calculations
– Bad_Pan
Nov 26 '18 at 8:14
1
1
Well, code from
ngAfterViewInit is executed right away (at least, most likely within a second), while your service's promises become initialized only after a second (setTimeout being async). Therefore, when Promise.all([this.appSrvc.p1, this.appSrvc.p2]) is executed, said promises are still null. What exactly are you trying to accomplish / what is the purpose of setTimeout here?– Jeto
Nov 26 '18 at 7:58
Well, code from
ngAfterViewInit is executed right away (at least, most likely within a second), while your service's promises become initialized only after a second (setTimeout being async). Therefore, when Promise.all([this.appSrvc.p1, this.appSrvc.p2]) is executed, said promises are still null. What exactly are you trying to accomplish / what is the purpose of setTimeout here?– Jeto
Nov 26 '18 at 7:58
Ok I understand but how can I resolve this problem? Where do I need to have the Promise.all in my component in order to wait the promises until they resolved
– Bad_Pan
Nov 26 '18 at 8:02
Ok I understand but how can I resolve this problem? Where do I need to have the Promise.all in my component in order to wait the promises until they resolved
– Bad_Pan
Nov 26 '18 at 8:02
You didn't answer that question at the end of my comment: what are you trying to accomplish?
Promise.all already does what you need, it waits until promises are resolved before doing something else.– Jeto
Nov 26 '18 at 8:03
You didn't answer that question at the end of my comment: what are you trying to accomplish?
Promise.all already does what you need, it waits until promises are resolved before doing something else.– Jeto
Nov 26 '18 at 8:03
I think you should switch to observable. Promise is concept that has fundamentally one application making ajax request. It was not design to do anything else.
– piotr szybicki
Nov 26 '18 at 8:11
I think you should switch to observable. Promise is concept that has fundamentally one application making ajax request. It was not design to do anything else.
– piotr szybicki
Nov 26 '18 at 8:11
setTimeout is just to emulate the time that is spent for data retrieval from other services and different calculations
– Bad_Pan
Nov 26 '18 at 8:14
setTimeout is just to emulate the time that is spent for data retrieval from other services and different calculations
– Bad_Pan
Nov 26 '18 at 8:14
|
show 1 more comment
1 Answer
1
active
oldest
votes
What happens is:
AppServiceconstructor is called at the moment of it's injection into the module- Few ms after that the
AppComponentis injected - About 100 ms later
AppComponent=>ngAfterViewInit()is called
When you set the timeout, the initialization of those two promises is postponed 1000ms. At that point your AppComponent=>ngAfterViewInit() is already done and values of those two what-will-be promises is actually undefined. To fix this you need to sync those two events, thus calling AppService.initialize() from AppComponent will do the trick but you also must make it async.
Here's an example how you can sync this:
getPromise1() {
if(!this.p1) {
return this.p1 = new Promise((resolve, reject) => {
resolve(true);
});
}
return this.p1;
}
getPromise2() {
if(!this.p2) {
return this.p2 = new Promise((resolve, reject) => {
setTimeout(() => resolve(true), 5000);
});
}
return this.p2;
}
And then at the call site:
ngAfterViewInit(){
Promise.all([this.appSrvc.getPromise1(), this.appSrvc.getPromise2()])
.then(values => {
console.log(values);
//If all promises resolved then execute something here
})
.catch(error => {
console.log(error.message)
});
}
Huh...setTimeoutdoes not return a Promise?
– Jeto
Nov 26 '18 at 8:25
You're right, i've switched to $timeout of AngularJS, whoops
– maljukan
Nov 26 '18 at 8:29
@Jeto I think i've added an answer after you already made quite the same in the comment of the question. If you make it in an answer i will remove mine.
– maljukan
Nov 26 '18 at 8:46
Since there's no DOM reading, I thinkngOnInitis more appropriate
– Cristian Traìna
Nov 26 '18 at 8:49
@maljukan It's OK!
– Jeto
Nov 26 '18 at 10:03
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53476482%2fangular-promise-all-in-timeout-event-not-working%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
What happens is:
AppServiceconstructor is called at the moment of it's injection into the module- Few ms after that the
AppComponentis injected - About 100 ms later
AppComponent=>ngAfterViewInit()is called
When you set the timeout, the initialization of those two promises is postponed 1000ms. At that point your AppComponent=>ngAfterViewInit() is already done and values of those two what-will-be promises is actually undefined. To fix this you need to sync those two events, thus calling AppService.initialize() from AppComponent will do the trick but you also must make it async.
Here's an example how you can sync this:
getPromise1() {
if(!this.p1) {
return this.p1 = new Promise((resolve, reject) => {
resolve(true);
});
}
return this.p1;
}
getPromise2() {
if(!this.p2) {
return this.p2 = new Promise((resolve, reject) => {
setTimeout(() => resolve(true), 5000);
});
}
return this.p2;
}
And then at the call site:
ngAfterViewInit(){
Promise.all([this.appSrvc.getPromise1(), this.appSrvc.getPromise2()])
.then(values => {
console.log(values);
//If all promises resolved then execute something here
})
.catch(error => {
console.log(error.message)
});
}
Huh...setTimeoutdoes not return a Promise?
– Jeto
Nov 26 '18 at 8:25
You're right, i've switched to $timeout of AngularJS, whoops
– maljukan
Nov 26 '18 at 8:29
@Jeto I think i've added an answer after you already made quite the same in the comment of the question. If you make it in an answer i will remove mine.
– maljukan
Nov 26 '18 at 8:46
Since there's no DOM reading, I thinkngOnInitis more appropriate
– Cristian Traìna
Nov 26 '18 at 8:49
@maljukan It's OK!
– Jeto
Nov 26 '18 at 10:03
add a comment |
What happens is:
AppServiceconstructor is called at the moment of it's injection into the module- Few ms after that the
AppComponentis injected - About 100 ms later
AppComponent=>ngAfterViewInit()is called
When you set the timeout, the initialization of those two promises is postponed 1000ms. At that point your AppComponent=>ngAfterViewInit() is already done and values of those two what-will-be promises is actually undefined. To fix this you need to sync those two events, thus calling AppService.initialize() from AppComponent will do the trick but you also must make it async.
Here's an example how you can sync this:
getPromise1() {
if(!this.p1) {
return this.p1 = new Promise((resolve, reject) => {
resolve(true);
});
}
return this.p1;
}
getPromise2() {
if(!this.p2) {
return this.p2 = new Promise((resolve, reject) => {
setTimeout(() => resolve(true), 5000);
});
}
return this.p2;
}
And then at the call site:
ngAfterViewInit(){
Promise.all([this.appSrvc.getPromise1(), this.appSrvc.getPromise2()])
.then(values => {
console.log(values);
//If all promises resolved then execute something here
})
.catch(error => {
console.log(error.message)
});
}
Huh...setTimeoutdoes not return a Promise?
– Jeto
Nov 26 '18 at 8:25
You're right, i've switched to $timeout of AngularJS, whoops
– maljukan
Nov 26 '18 at 8:29
@Jeto I think i've added an answer after you already made quite the same in the comment of the question. If you make it in an answer i will remove mine.
– maljukan
Nov 26 '18 at 8:46
Since there's no DOM reading, I thinkngOnInitis more appropriate
– Cristian Traìna
Nov 26 '18 at 8:49
@maljukan It's OK!
– Jeto
Nov 26 '18 at 10:03
add a comment |
What happens is:
AppServiceconstructor is called at the moment of it's injection into the module- Few ms after that the
AppComponentis injected - About 100 ms later
AppComponent=>ngAfterViewInit()is called
When you set the timeout, the initialization of those two promises is postponed 1000ms. At that point your AppComponent=>ngAfterViewInit() is already done and values of those two what-will-be promises is actually undefined. To fix this you need to sync those two events, thus calling AppService.initialize() from AppComponent will do the trick but you also must make it async.
Here's an example how you can sync this:
getPromise1() {
if(!this.p1) {
return this.p1 = new Promise((resolve, reject) => {
resolve(true);
});
}
return this.p1;
}
getPromise2() {
if(!this.p2) {
return this.p2 = new Promise((resolve, reject) => {
setTimeout(() => resolve(true), 5000);
});
}
return this.p2;
}
And then at the call site:
ngAfterViewInit(){
Promise.all([this.appSrvc.getPromise1(), this.appSrvc.getPromise2()])
.then(values => {
console.log(values);
//If all promises resolved then execute something here
})
.catch(error => {
console.log(error.message)
});
}
What happens is:
AppServiceconstructor is called at the moment of it's injection into the module- Few ms after that the
AppComponentis injected - About 100 ms later
AppComponent=>ngAfterViewInit()is called
When you set the timeout, the initialization of those two promises is postponed 1000ms. At that point your AppComponent=>ngAfterViewInit() is already done and values of those two what-will-be promises is actually undefined. To fix this you need to sync those two events, thus calling AppService.initialize() from AppComponent will do the trick but you also must make it async.
Here's an example how you can sync this:
getPromise1() {
if(!this.p1) {
return this.p1 = new Promise((resolve, reject) => {
resolve(true);
});
}
return this.p1;
}
getPromise2() {
if(!this.p2) {
return this.p2 = new Promise((resolve, reject) => {
setTimeout(() => resolve(true), 5000);
});
}
return this.p2;
}
And then at the call site:
ngAfterViewInit(){
Promise.all([this.appSrvc.getPromise1(), this.appSrvc.getPromise2()])
.then(values => {
console.log(values);
//If all promises resolved then execute something here
})
.catch(error => {
console.log(error.message)
});
}
edited Nov 26 '18 at 9:12
answered Nov 26 '18 at 8:12
maljukanmaljukan
1,0341929
1,0341929
Huh...setTimeoutdoes not return a Promise?
– Jeto
Nov 26 '18 at 8:25
You're right, i've switched to $timeout of AngularJS, whoops
– maljukan
Nov 26 '18 at 8:29
@Jeto I think i've added an answer after you already made quite the same in the comment of the question. If you make it in an answer i will remove mine.
– maljukan
Nov 26 '18 at 8:46
Since there's no DOM reading, I thinkngOnInitis more appropriate
– Cristian Traìna
Nov 26 '18 at 8:49
@maljukan It's OK!
– Jeto
Nov 26 '18 at 10:03
add a comment |
Huh...setTimeoutdoes not return a Promise?
– Jeto
Nov 26 '18 at 8:25
You're right, i've switched to $timeout of AngularJS, whoops
– maljukan
Nov 26 '18 at 8:29
@Jeto I think i've added an answer after you already made quite the same in the comment of the question. If you make it in an answer i will remove mine.
– maljukan
Nov 26 '18 at 8:46
Since there's no DOM reading, I thinkngOnInitis more appropriate
– Cristian Traìna
Nov 26 '18 at 8:49
@maljukan It's OK!
– Jeto
Nov 26 '18 at 10:03
Huh...
setTimeout does not return a Promise?– Jeto
Nov 26 '18 at 8:25
Huh...
setTimeout does not return a Promise?– Jeto
Nov 26 '18 at 8:25
You're right, i've switched to $timeout of AngularJS, whoops
– maljukan
Nov 26 '18 at 8:29
You're right, i've switched to $timeout of AngularJS, whoops
– maljukan
Nov 26 '18 at 8:29
@Jeto I think i've added an answer after you already made quite the same in the comment of the question. If you make it in an answer i will remove mine.
– maljukan
Nov 26 '18 at 8:46
@Jeto I think i've added an answer after you already made quite the same in the comment of the question. If you make it in an answer i will remove mine.
– maljukan
Nov 26 '18 at 8:46
Since there's no DOM reading, I think
ngOnInit is more appropriate– Cristian Traìna
Nov 26 '18 at 8:49
Since there's no DOM reading, I think
ngOnInit is more appropriate– Cristian Traìna
Nov 26 '18 at 8:49
@maljukan It's OK!
– Jeto
Nov 26 '18 at 10:03
@maljukan It's OK!
– Jeto
Nov 26 '18 at 10:03
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53476482%2fangular-promise-all-in-timeout-event-not-working%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Well, code from
ngAfterViewInitis executed right away (at least, most likely within a second), while your service's promises become initialized only after a second (setTimeoutbeing async). Therefore, whenPromise.all([this.appSrvc.p1, this.appSrvc.p2])is executed, said promises are still null. What exactly are you trying to accomplish / what is the purpose ofsetTimeouthere?– Jeto
Nov 26 '18 at 7:58
Ok I understand but how can I resolve this problem? Where do I need to have the Promise.all in my component in order to wait the promises until they resolved
– Bad_Pan
Nov 26 '18 at 8:02
You didn't answer that question at the end of my comment: what are you trying to accomplish?
Promise.allalready does what you need, it waits until promises are resolved before doing something else.– Jeto
Nov 26 '18 at 8:03
I think you should switch to observable. Promise is concept that has fundamentally one application making ajax request. It was not design to do anything else.
– piotr szybicki
Nov 26 '18 at 8:11
setTimeout is just to emulate the time that is spent for data retrieval from other services and different calculations
– Bad_Pan
Nov 26 '18 at 8:14