Avoid Multiple Http Calls in Dialog onInit

16 views
Skip to first unread message

Haley Lohrenz

unread,
Apr 28, 2020, 5:48:19 AM4/28/20
to Angular and AngularJS discussion
Hello everybody! I'm relatively new here, but have been using Angular for roughly 3 years now. However, I'm stumped on how to avoid multiple http calls in the ngOnInit method of a material dialog (or any dialog for that matter). I'm retrieving a list of data for the form (one of the select options) inside my dialog, but it is called every time I open it which I view as a bad thing especially if you are editing more than one entity at a time (opening multiple dialogs over time). How do you devs handle this situation? Do you pass it from your component that calls the dialog so it only has one subscription in there? So any data you need in your dialog form, you would pull from the parent even if they never open a dialog? It's the only remedy I can think of, just don't know how hacky it is.

bastien lemaire

unread,
Apr 28, 2020, 6:32:45 AM4/28/20
to Angular and AngularJS discussion
Hi, Could you post a stacklitz with the minimum reproduction code, please?

Arnaud Deman

unread,
Apr 30, 2020, 9:37:30 AM4/30/20
to Angular and AngularJS discussion
Hi,
If the http call is done in a service you could use the Share operator.
Regards,
Arnaud.
Reply all
Reply to author
Forward
0 new messages