为什么$ routeChangeSuccess不会被调用? [英] why $routeChangeSuccess never gets called?
问题描述
我做我的应用程序类似下面的东西,但我只是不能够得到routeChangeSuccess事件。
I am doing something similar to below on my app but I am just not able to get the routeChangeSuccess event.
var myapp = angular.module('myapp', ["ui.router", "ngRoute"]);
myapp.controller("home.RootController",
function($rootScope, $scope, $location, $route) {
$scope.menus = [{ 'name': 'Home ', 'link': '#/home'}, {'name': 'services', 'link': '#/services'} ]
$scope.$on('$routeChangeSuccess', function(event, current) {
alert('route changed');
});
}
);
myapp.config(
function($stateProvider, $urlRouterProvider, $routeProvider) {
$urlRouterProvider.otherwise("/home");
$stateProvider
.state('home', {
url: "/home",
//template: '<h1>Home Screen</h1>'
templateUrl: "/Client/Views/Home/Home.htm"
})
.state('services', {
url: "/services",
//template: '<h1>Service screen</h1>'
templateUrl: "/Client/Views/Home/service.htm"
});
});
一个非常简单的HTML如下也会失败
a very simple html as below also fails
<body ng-controller="home.RootController">
<ul class="nav">
<li ng-repeat="menu in menus" "="">
<a href="{{menu.link}}">{{menu.name}}</a>
</li>
</ul>
<div ui-view> No data yet!</div>
</body>
但是当我点击链接我看到的看法越来越更新,但$ routeChangeSucces事件被触发从不
but when i click on the link i see that the views are getting updated but the $routeChangeSucces event is never triggered.
是有什么我失踪?
另一个问题我是在那里我可以勾上知道的看法是准备好这样我就可以启动一些额外的处理,像的document.ready()的事件。
Another question I had was is there an event that I can hook on to to know the view is ready so I can start some additional processing, like document.ready().
plnlr 但不完全工作...
plnlr but not fully working...
问候
基兰
推荐答案
请检查这个wiki:的 State Change事件的。摘录:
Please, check this wiki: State Change Events. An extract:
-
$ stateChangeSuccess - 燃煤一旦国家完成过渡
$stateChangeSuccess - fired once the state transition is complete.
$范围。在$('$ stateChangeSuccess',结果
功能(事件,toState,toParams,fromState,fromParams){...})
$scope.$on('$stateChangeSuccess',
function(event, toState, toParams, fromState, fromParams){ ... })
因此而不是 $ routeChangeSuccess
使用 $ stateChangeSuccess
。
要获得关于所有可用事件的更详细信息,请查看维基活动。的在这里你可以发现适合你,可能是事件的 $ viewContentLoaded
... 的
To get more detailed information about all available events, check the wiki Events. Here you can find that the suitable for you, could be event $viewContentLoaded
...
这篇关于为什么$ routeChangeSuccess不会被调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!