I have a single page app built using AngularJS. When the page first loads, there are two controllers that execute and these are 'Controller1' and 'Controller2'.
- Each of them needs to make a call to the same WebAPI in order to meet its logic requirements.
- Also, 'Controller1' code executes first, but due to the async nature of the code, 'Conroller2' code starts to execute before the Controller1 call to WebAPI has returned successfully.
Question: How can I make sure that only Controller1 makes the call to WebAPI, so that Controller2 simply uses the call in Controller1 rather than making a repeated call?
Controller1
dashboardDataService.getAllDashboards().then(onDashboardListReceived)
Controller2
dashboardDataService.getAllDashboards().then(onDashboardListReceived)