Home » Angularjs » How can I trigger an event when an angular JS route template has been loaded

How can I trigger an event when an angular JS route template has been loaded

Posted by: admin November 29, 2017 Leave a comment

Questions:

Does anyone know how to trigger an event when an angular route has rendered its view? I’d like to route the application and at the end of the template being rendered I would like it to trigger an event to slide the view “open”, so that the User Experience isnt so harsh. When you click on a link the route chnages so quick. I basically want to make the User Experience smoother.

  1. click an image
  2. routes the application (but the view has a class of display none
  3. when the view is done loading then I want to trigger an event
  4. the event triggers a listener that makes my markup slide down and open up.

Any ideas?

Answers:

Does this do what you’re after?

$scope.$on('$routeChangeSuccess', function () {
  // run some code to do your animations
});

Go to http://docs.angularjs.org/api/ and take a look at $route (LHS menu under ngRoute module)

Or take a look at this question I asked….AngularJS – Animate ng-view transitions