简体   繁体   English

在UI路由器中将嵌套状态用作选项卡

[英]Use nested states as tabs in ui-router

The documentation seems a little sparse on this particular case, however I'm working off of the "Multiple Views About Page" section of this tutorial, which is supported by this SO post. 在这种特殊情况下,文档似乎有些稀疏,但是我正在教程的“关于页面的多视图”部分中进行工作, SO帖子对此提供了支持。

I'm trying to convert one of my pages to a parent state that renders each tab as child states. 我正在尝试将我的页面之一转换为将每个选项卡呈现为子状态的父状态。 The syntax below doesn't throw an error, however only the tab headers are rendering, none of the content. 下面的语法不会引发错误,但是仅呈现选项卡标题,而没有内容。 I've set breakpoints in the init functions in the child controllers and nothing fires, and I'm not getting any errors back in the console. 我已经在子控制器的init函数中设置了断点,并且没有任何反应,并且在控制台中没有出现任何错误。 I've also created a breakpoint in the $stateChangeError callback and am getting nothing in there as well. 我还在$stateChangeError回调中创建了一个断点,那里也什么也没有。

parent state 母国

<div class="container">
    <h2> <i class="fa fa-user"></i> Click to Call Settings for {{user.fullName}}</h2>
    <uib-tabset active="active" id="usersettings">
        <uib-tab index="0" heading="SIP Settings"> 
            <div ui-view="sipSettings"></div> 
        </uib-tab>   
        <uib-tab index="1" heading="Favorites"> 
            <div ui-view="favorites"></div>       
        </uib-tab>
    </uib-tabset>  
</div>>

favoritesPartial.html (edited for the sake of space) favoritePartial.html(为节省空间而进行了编辑)

<form name="favoritesForm">
    <div ng-repeat="favorite in pbxFavorites" id="favoritesContainer">

    </div>
</form>
<div class="form-footer">
    <button type="button" class="btn btn-white" ng-click="$root.goBack()">Go Back</button>
    <button type="submit" class="btn btn-primary" ng-click="saveFavorites()">Save Favorites</button>
</div> 

sipSettingsPartial.html (edited for the sake of space) sipSettingsPartial.html(为节省空间而进行了编辑)

<form name="sipSettingsForm">
    <div class="row">

    <div class="form-footer">
        <button type="button" class="btn btn-white" ng-click="$root.goBack()">Go Back</button>
        <button type="submit" class="btn btn-primary" ng-click="savePbxSettings()">Save Settings</button>
    </div>  
 </form>

state provider 国家提供者

        .state('clickToCall', {
            url: '/clickToCall',
            templateUrl: 'app/components/clickToCall/clickToCall.html',
            controller: 'ClickToCallController',
            controllerAs: 'vm',
            parent: 'app',
            authenticate: true,
            resolvePolicy: {when:'LAZY', async: 'WAIT'},
            resolve:{
                security:['$q', '$rootScope', 'parentResolves',  'routeErrors', function($q, $rootScope, parentResolves, routeErrors){
                    if($rootScope.isLoggedIn()){
                        return $q.resolve();
                    } else {
                        return $q.reject(routeErrors.NO_ACCESS);
                    }
                }]
            },
            params:{
                'user':''
            },
            view:{
                'sipSettings@clickToCall': {
                    templateUrl: 'app/components/clickToCall/sipSettingsPartial.html',
                    controller: 'SipSettingsController'
                },
                'favorites@clickToCall':{
                    templateUrl: 'app/components/clickToCall/favoritesPartial.html',
                    controller: 'FavoritesController'
                }
            }
        })

folder structure 文件夹结构

在此处输入图片说明

screen shot 屏幕截图

在此处输入图片说明

Stupid typo...... named the section view instead of views , also left the templateUrl in the parent state. 愚蠢的拼写错误……命名为截面view而不是views ,这也使templateUrl处于父状态。 The following config works: 以下配置有效:

        .state('clickToCall', {
            url: '/clickToCall',
            controller: 'ClickToCallController',
            controllerAs: 'vm',
            parent: 'app',
            authenticate: true,
            resolvePolicy: {when:'LAZY', async: 'WAIT'},
            resolve:{
                security:['$q', '$rootScope', 'parentResolves',  'routeErrors', function($q, $rootScope, parentResolves, routeErrors){
                    if($rootScope.isFirmAdmin2 || $rootScope.isCloud9){
                        return $q.resolve();
                    } else {
                        return $q.reject(routeErrors.NO_ACCESS);
                    }
                }]
            },
            params:{
                'user':''
            },
            views:{
                '':{
                    templateUrl: 'app/components/clickToCall/clickToCall.html'
                },
                'sipSettings@clickToCall': {
                    templateUrl: 'app/components/clickToCall/sipSettingsPartial.html',
                    controller: 'SipSettingsController'
                },
                'favorites@clickToCall':{
                    templateUrl: 'app/components/clickToCall/favoritesPartial.html',
                    controller: 'FavoritesController'
                }
            }
        })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM