Angular ui-router to accomplish a conditional view

前端 未结 4 1298
春和景丽
春和景丽 2020-12-31 11:46

I am asking a similar question to this question: UI Router conditional ui views?, but my situation is a little more complex and I cannot seem to get the provided answer to w

4条回答
  •  暖寄归人
    2020-12-31 12:31

    Use verified code for 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);
            }]
          });
    

提交回复
热议问题