Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 541
Subtubes Avatar asked Mar 27 '13 21:03

Subtubes


People also ask

Which event defined by the route service is triggered after the route has changed?

The $on() method is an event handler, the event which will handle $routeChangeSuccess which gets triggered when route/view change is done.

How do AngularJS routes work?

AngularJS routes enable the user to create different URLs for different content in an application. The ngRoute module helps in accessing different pages of an application without reloading the entire application. Important: $routeProvider is used to configure the routes.


1 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

like image 59
Greg Avatar answered Oct 17 '22 05:10

Greg