【问题标题】:Ionic tabs : child view not showing离子标签:子视图不显示
【发布时间】:2015-09-09 01:31:16
【问题描述】:

我将应用的导航从侧边菜单更改为底部标签。 (tabs)。

它适用于父页面,但不显示任何子页面。

我遵循了入门应用提供的代码以及doc 提供的代码。

所以我做了什么:

tabs.html:

<ion-tabs class="tabs-icon-only tabs-color-calm">

    <!-- Home Tab -->
    <ion-tab title="Home" icon-off="ion-home" icon-on="ion-home" ui-sref="tab.users">
        <ion-nav-view name="tab-users"></ion-nav-view>
    </ion-tab>

    <!-- Conversations Tab -->
    <ion-tab title="Conversations" icon-off="ion-email" icon-on="ion-email" ui-sref="tab.conversations">
        <ion-nav-view name="tab-conversations"></ion-nav-view>
    </ion-tab>

    <!-- Profile Tab -->
    <ion-tab title="Profile" icon-off="ion-person" icon-on="ion-person" ui-sref="tab.profile">
        <ion-nav-view name="tab-profile"></ion-nav-view>
    </ion-tab>

</ion-tabs>

tab-users.html(父):

<ion-view view-title="List users">
    <ion-content>

        <div ng-repeat="user in users">
            <a class="item item-avatar" ui-sref="tab.user({id:user.id})">
                <h2>{{ user.firstname }} {{ user.lastname }}
            </a>
        </div>

    </ion-content>
</ion-view>

user.html(tab-users 的子级,未显示的那个):

 <ion-view view-title="{{ user.firstname }} {{ user.lastname }}">
    <ion-content>

        {{ user.firstname }} {{ user.lastname }}

    </ion-content>
</ion-view>

路线:

$stateProvider

    // setup an abstract state for the tabs directive
    .state('tab', {
        url: '/tab',
        abstract: true,
        templateUrl: 'templates/tabs.html'
    })

    // Each tab has its own nav history stack:

    // Users (Home) :

    .state('tab.users', {
            url: '/users',
            views: {
                'tab-users': {
                    controller: 'NetworkController',
                    templateUrl: 'templates/tab-users.html'
                }
            }
        })
        .state('tab.user', {
            url: '/user/:id',
            view: {
                'tab-users': {
                    controller: 'UserController',
                    templateUrl: 'templates/user.html'
                }
            }
        })

    // Conversations :

    .state('tab.conversations', {
            url: '/messages',
            views: {
                'tab-conversations': {
                    controller: 'ConversationsController',
                    templateUrl: 'templates/tab-conversations.html'

                }
            }
        })
        .state('tab.conversation-messages', {
            url: '/messages/:id',
            view: {
                'tab-conversations':{
                    controller: 'MessagesController',
                    templateUrl: 'templates/conversation-messages.html'

                }
            }
        })

    // Profile :

    .state('tab.profile', {
            url: '/profile',
            views: {
                'tab-profile': {
                    controller: 'ProfileController',
                    templateUrl: 'templates/tab-profile.html'

                }
            }
        })
        .state('tab.profile-preferences', {
            url: '/profile/:slug',
            view: {
                'tab-profile': {
                    controller: 'PreferenceController',
                    templateUrl: 'templates/profile-preferences.html'

                }
            }
        })

    // Others :

    .state('login', {
        url: '/login',
        templateUrl: 'templates/login.html',
    })

    .state('register', {
        url: '/register',
        templateUrl: 'templates/register.html'
    })

;

$urlRouterProvider.otherwise("/tab/users");

index.html:

<body ng-app="ionicApp" ng-controller="ApplicationController">

    <div ng-show="error.status == true" class="bar bar-subheader bar-error">
        <div class="error-bg"></div>
        <div class="statusText"><strong>Error ({{ error.code }}) :</strong> {{ error.statusText }}</div>
        <i class="icon ion-close-round" ng-click="error.status = false"></i>
    </div>

    <ion-nav-bar class="bar-calm">
        <ion-nav-back-button class="button-clear"><i class="ion-arrow-left-c"></i> Back</ion-nav-back-button>
        <ion-nav-buttons side="right">
            <button class="button button-icon button-clear ion-archive"></button>
        </ion-nav-buttons>
    </ion-nav-bar>

    <ion-nav-view></ion-nav-view>

</body>

更新:

请注意,ui-sref 正确生成了到 /tab/user/15 的路由

【问题讨论】:

    标签: angularjs angular-ui-router ionic-framework angular-ui ionic


    【解决方案1】:

    a working plunker

    似乎有/只是一个错字

    而且不止一个!第一个(已在问题编辑中修复)

    • views : { 'tabs-users' ...}
    • 应该是views : { 'tab-users' ...}

    起始 tab- 代替 tabs-

    .state('tab.users', {
        url: '/users',
        views: {
            'tab-users': {
            ...
    
    .state('tab.user', {
        url: '/user/:id',
        view: {
            // not working
            'tabs-users': {
            // should be
            'tab-users': {
    

    因为目标名称是:

    <ion-nav-view name="tab-users"></ion-nav-view>
    

    第二个是......我们需要使用 views :{} 而不是 view : {}

    .state('tab.user', {
        url: '/user/:id',
        // wrong
        view: {
        // working
        views: {
            // not working
            'tabs-users': {
            // should be
            'tab-users': {
    

    在行动中检查它here

    【讨论】:

    • 对,那个有错字,但其他标签的其他孩子也不起作用。它没有解决它,但感谢您纠正错字;)。
    • 为什么你改变了你的问题 - 并修正了错字?那是一个真正的问题。错字是必不可少的......因为每个状态都被注入到名为例如的父视图(它应该是“标签”状态)中'标签用户'。这就是 UI-Router 的工作方式。此外,如果您要更改您的问题.. 最好查看列表的内容 - 您如何生成指向详细信息的链接...
    • 因为它没有解决问题。所以为了不误导任何人,我更新了代码。但是是的,我确实理解该视图应该与 ion-nav-view 中声明的相同。当然我会更新代码。
    • 我让你的代码工作了。还提供了一个工作的plunker。似乎拼写错误是您的问题...希望对您有所帮助。享受离子
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多