本文介绍了UI-router $stateChangeStart 根本不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的 app.js
this is my app.js
var $stateProviderRef = null;
var $urlRouterProviderRef = null;
var acadb = angular.module('acadb', [
'ngRoute',
'ui.router',
'ngAnimate',
'ui.bootstrap',
'acadb.controllers',
'acadb.services',
'acadb.filters',
'acadb.directives',
'ngResource',
'angularMoment',
'angularFileUpload',
'ui.materialize',
'angular-toArrayFilter',
'ngSanitize',
'metatags',
])
.run(['$rootScope', '$state', '$stateParams','$http', function($rootScope, $state, $stateParams,$http) {
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
}])
.config(['$locationProvider', '$stateProvider', '$urlRouterProvider', '$httpProvider',
function($locationProvider, $stateProvider, $urlRouterProvider, $httpProvider) {
// XSRF token naming
$httpProvider.defaults.xsrfHeaderName = 'x-dt-csrf-header';
$httpProvider.defaults.xsrfCookieName = 'X-CSRF-TOKEN';
//$httpProvider.interceptors.push('httpInterceptor');
$urlRouterProvider.otherwise("/");
$stateProvider
.state('home', {
url: "/",
templateUrl: '/partials/tpl/welcome.html',
})
.state('jobseeker', {
url: "/jobseeker",
templateUrl: '/partials/dashboard.php',
})
.state('register', {
url: "/register",
templateUrl: '/partials/auth/register.blade.php',
})
.state('login', {
url: "/login",
templateUrl: '/partials/tpl/login.html',
})
$locationProvider.html5Mode({
enabled: false
});
$stateProviderRef = $stateProvider;
$urlRouterProviderRef = $urlRouterProvider;
}])
.run(function($rootScope, $location, AuthenticationService, FlashService, MetaTags,$state ) {
console.log('ds');
$rootScope.$on('$stateChangeStart', function(event, next, current) {
event.preventDefault();
console.log('sd');
//if(!AuthenticationService.isLoggedIn()) {
// console.log(current);
// console.log(next);
//
//
//
// event.preventDefault();
// $state.go('login');
// FlashService.show("Please log in to continue.");
//}
//
});
}
)
我在生活中真正想要的只是在状态更改时控制台记录一个字符串..为什么第二个控制台日志没有在 stateChangeStart 上触发?
all i realy want in life is just to console log a string on a state change..why doesnt the second console log fire on stateChangeStart?
这令人沮丧.我在另一个运行良好的应用程序中有完全相同的逻辑
this is frustrating.i have the exact same logic in another app that is working just fine
推荐答案
要启用这些状态事件,请在您的项目中包含 stateEvents.js 文件,例如,
To enable these state events, include the stateEvents.js file in your project, e.g.,
<script src="stateEvents.js"></script>
并确保您依赖于 ui.router.state.events 角度模块,例如,
and also make sure you depend on the ui.router.state.events angular module, e.g.,
angular.module("myApplication", ['ui.router', 'ui.router.state.events']
https://ui-router.github.io/ng1/docs/latest/modules/ng1_state_events.html
这篇关于UI-router $stateChangeStart 根本不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!