javascript 加载 Angular JS 路由模板后如何触发事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15669827/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 01:37:17  来源:igfitidea点击:

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

javascriptjqueryangularjsangularjs-directive

提问by Edgar Martinez

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.
  1. 单击图像
  2. 路由应用程序(但视图有一类显示无
  3. 当视图加载完成后,我想触发一个事件
  4. 该事件触发一个侦听器,使我的标记向下滑动并打开。

Any ideas?

有任何想法吗?

回答by Greg

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)

转到http://docs.angularjs.org/api/并查看$route(ngRoute 模块下的 LHS 菜单)

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

或者看看我问的这个问题...... AngularJS - Animate ng-view transitions