UI Router conditional ui views?

后端 未结 9 1168
遥遥无期
遥遥无期 2021-01-30 21:23

I can\'t figure out a reasonable way, which doesn\'t feel like a hack, to solve this rather trivial problem.

I want a guest to see a splash page when they access the ind

相关标签:
9条回答
  • 2021-01-30 21:50

    In my case, if two states can share logic of same controller, conditional template is a good choice. Otherwise, creating separate states is a good option.

    0 讨论(0)
  • 2021-01-30 21:56

    For docs purposes, I used:

    $rootScope.$on('$stateChangeStart', function(event, toState) {
      if ((toState.name !== 'login') && (!$localStorage.nickname)) {
        event.preventDefault();
        $state.go('login');
      }
    });
    

    Using $routeChangeStart didn't work for me.

    0 讨论(0)
  • 2021-01-30 21:59

    It is used for me conditional view in ui-route

    $stateProvider.state('dashboard.home', {
            url: '/dashboard',
            controller: 'MainCtrl',
           // templateUrl: $rootScope.active_admin_template,
            templateProvider: ['$stateParams', '$templateRequest','$rootScope', function ($stateParams, templateRequest,$rootScope) {
              var templateUrl ='';
              if ($rootScope.current_user.role == 'MANAGER'){
                templateUrl ='views/manager_portal/dashboard.html';
              }else{
                templateUrl ='views/dashboard/home.html';
              }
              return templateRequest(templateUrl);
            }]
          });
    
    0 讨论(0)
提交回复
热议问题