UI路由器$ stateChangeStart根本不起作用 [英] UI-router $stateChangeStart not working at all

查看:121
本文介绍了UI路由器$ 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路由器$ stateChangeStart根本不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆