The Workout Builder page in Personal Trainer depends upon the resolve
route configuration to inject the selected workout into WorkoutDetailController
.
The resolve
configuration has an additional advantage if any of the resolve functions return a promise like the selectedWorkout
function:
return WorkoutBuilderService.startBuilding($route.current.params.id);
When the promise is resolved successfully, the data is injected into the controller, but what happens on promise rejection or error? The preceding promise can fail if we enter a random workout name in the URL such as /builder/workouts/dummy
and try to navigate, or if there is a server error. With a failed promise, two things happen:
Firstly, the app route does not change. If you refresh the page using the browser, the complete content is cleared.
Secondly, a
$routeChangeError
event is broadcasted on$rootScope
(remember Angular events$emit
and$broadcast
).
We can use this event to give visual clues...