fbpx Skip to content

Aquent | DEV6

AngularJS – $route.reload()

Written by: Alain Thibodeau

Routes are an integral part of AngularJS. Taking a look at the $route’s documentation we will notice that route has a reload method. Taking a closer look at this method reveals that the current route and therefore its controller will be refreshed.

This feature can be very useful. Let’s say the route’s controller has services that are called when the controller is instantiated and you need to re-call those exact same services when some condition happens to refresh the data. All you would need to do is call $route.reload(). This will reload the route (not refresh page) which will re-instantiate the controller and therefore recall the services.

Taking advantage of injection, you can call reload anywhere in your application.

Example using an App Controller:

app.controller('AppController', ['$scope', '$route', function ($scope, $route) {
$scope.reloadRoute = function () {
$route.reload();
};
}]);

Sign up for our Angular Course

Learn the most recent version and start building your own Angular apps

view course details