Angularjs $stateChangeStart don';用户刷新浏览器时无法工作
请, 我正在我的项目中使用ui路由器<代码>$stateChangeStart当用户在状态之间导航时,事件工作正常。 但是如果我刷新浏览器,它就不起作用了 这是我的源代码:Angularjs $stateChangeStart don';用户刷新浏览器时无法工作,angularjs,events,angular-ui-router,state,Angularjs,Events,Angular Ui Router,State,请, 我正在我的项目中使用ui路由器$stateChangeStart当用户在状态之间导航时,事件工作正常。 但是如果我刷新浏览器,它就不起作用了 这是我的源代码: (function(){ 'use strict'; angular.module('app.overlay') .directive('ibLoading', ['$rootScope' , '$timeout', loading]); function loading($rootScope , $timeou
(function(){
'use strict';
angular.module('app.overlay')
.directive('ibLoading', ['$rootScope' , '$timeout', loading]);
function loading($rootScope , $timeout){
console.log("In dirrective");
var directive = {
restrict:'EAC',
link:link
};
function link(scope, element) {
$rootScope.$on('$stateChangeStart', function() {
$timeout(function(){
element.addClass('show');
} , 50);
});
$rootScope.$on('$stateChangeSuccess', function() {
$timeout(function(){
element.removeClass('show');
} , 700);
});
}
return directive;
}
})();
我的布局文件
<div ng-controller="ShellController as vm">
<header class="clearfix">
<ht-top-nav navline="vm.navline"></ht-top-nav>
</header>
<section id="content" class="content">
<!--<div ng-include="'app/layout/sidebar.html'"></div>-->
<div ui-view></div>
<div class="ib-loading">Loading ...</div>
</section>
</div>
加载。。。
试试这个,在这里,如果您更改您的状态,您可以在控制台中看到您的状态,但如果您重新加载页面,它将重新加载状态
$rootScope.$on('$stateChangeStart', function (event, toState, toParams) {
console.log("Switching To: ", toState.name);
});
用户刷新不会触发$stateChangeStart或$stateChangeSuccess。但是,$viewContentLoading和$viewContentLoaded会触发 因此,您可以尝试以下方法:
$rootScope.$on('$viewContentLoading', function() {
$timeout(function(){
element.addClass('show');
} , 50);
});
$rootScope.$on('$viewContentLoaded', function() {
$timeout(function(){
element.removeClass('show');
} , 700);
});
你能提供一些代码示例吗?这取决于它的使用位置。没有任何代码,没有人能帮助你。请提供相关代码。您是否可以共享您的状态配置?你在哪里使用它?可能是一些示例代码,伪代码也会有帮助,@charlietft建议。。。没有信息指令在第页的何处使用?首先,应使用范围变量和
ng class
或ng show
完成此操作。此外,在编译指令之前,第一个状态更改可能已经开始了,这可能是个好消息!继续努力!是的,但是你不能用这些来占领这个州,或者有办法吗?