module.run() and $state.go() angularJS

后端 未结 7 2242
猫巷女王i
猫巷女王i 2021-02-12 12:38

I might have some kind of missunderstanding. Im using angular ui router and i have the next issue:

I have the next State provider:

angular
.module(\'Main         


        
7条回答
  •  悲&欢浪女
    2021-02-12 13:01

    It can sound strange but for me the solution was to rename my state and remove the dot ...

    I want an home page different for customer, director, manager or anything ( but with the same url )

      .state('home', {
        url : '/',
        templateUrl: 'views/home.html',
        controller: 'HomeCtrl',
        controllerAs: 'home',
        module :'private'
      })
      .state('home.customer', {
        url : '',
        templateUrl: 'views/home-customer.html',
        controller: 'HomeCustomerCtrl',
        controllerAs: 'homeCustomer',
        module :'private'
      })
    
      .run(function ($rootScope, $state, $window,userService) {
        $rootScope.$on("$stateChangeStart", function(e, toState, toParams, fromState, fromParams) {
         if(toState.name === 'home') {
              if(userService.isCustomer()) {
                   $state.go('home.customer');
             }
          }
    }
    

    This dosen't work, replace the name home.customer state with home-customer and $state.go('home-customer'); and it works ...

提交回复
热议问题