离子未加载标签页

Ionic Not Loading Tab Page

本文关键字:标签 加载      更新时间:2023-09-26
几天来我一直在为

这个问题而苦恼,我知道这是一件简单的事情,我早就应该注意到了,但对于我的生活,我无法弄清楚。

简单的问题:从起始页开始,单击我的选项卡的图标将切换到正确的 URL,但不加载页面内容或控制器。

我从 Ionic "选项卡"模板重新开始,只更改了必要的内容(或者我相信是这样)。

任何帮助,不胜感激。

应用.js

// Removed comments
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])
.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }
  });
})
.config(function($stateProvider, $urlRouterProvider) {
  // Removed comments, though I did check the github page given
  $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:
  .state('tab.dash', {
    url: '/dash',
    views: {
      'tab-dash': {
        templateUrl: 'templates/tab-dash.html',
        controller: 'DashCtrl'
      }
    }
  })
  .state('tab.chats', {
    url: '/chats',
    views: {
      'tab-chats': {
        templateUrl: 'templates/tab-chats.html',
        controller: 'ChatsCtrl'
      }
    }
  })
  .state('tab.chat-detail', {
    url: '/chats/:chatId',
    views: {
      'tab-chats': {
        templateUrl: 'templates/chat-detail.html',
        controller: 'ChatDetailCtrl'
      }
    }
  })
  .state('tab.account', {
    url: '/account',
    views: {
      'tab-account': {
        templateUrl: 'templates/tab-account.html',
        controller: 'AccountCtrl'
      }
    }
  })
  .state('tab.quickscan', {
    url: '/quickscan',
    templateUrl: 'templates/tab-quickscan.html',
    controller: 'QuickScanCtrl'
  });
  // if none of the above states are matched, use this as the fallback
  $urlRouterProvider.otherwise('/tab/dash');
});

控制器.js

angular.module('starter.controllers', [])
.controller('DashCtrl', function($scope) {})
.controller('ChatsCtrl', function($scope, Chats) {
  // Removed comments
  $scope.chats = Chats.all();
  $scope.remove = function(chat) {
    Chats.remove(chat);
  };
})
.controller('ChatDetailCtrl', function($scope, $stateParams, Chats) {
  $scope.chat = Chats.get($stateParams.chatId);
})
.controller('AccountCtrl', function($scope) {
  $scope.settings = {
    enableFriends: true
  };
})
.controller('QuickScanCtrl', function($scope) {
  console.log("QuickScanCtrl loaded");
});

选项卡.html

<!--
Create tabs with an icon and label, using the tabs-positive style.
Each tab's child <ion-nav-view> directive will have its own
navigation history that also transitions its views in and out.
-->
<ion-tabs class="tabs-icon-top tabs-color-active-positive">
  <!-- Dashboard Tab -->
  <ion-tab title="Status" icon-off="ion-ios-pulse" icon-on="ion-ios-pulse-strong" href="#/tab/dash">
    <ion-nav-view name="tab-dash"></ion-nav-view>
  </ion-tab>
  <!-- Chats Tab -->
  <ion-tab title="Chats" icon-off="ion-ios-chatboxes-outline" icon-on="ion-ios-chatboxes" href="#/tab/chats">
    <ion-nav-view name="tab-chats"></ion-nav-view>
  </ion-tab>
  <!-- Account Tab -->
  <ion-tab title="Account" icon-off="ion-ios-gear-outline" icon-on="ion-ios-gear" href="#/tab/account">
    <ion-nav-view name="tab-account"></ion-nav-view>
  </ion-tab>
  <!-- QuickScan Tab -->
  <ion-tab title="Quick Scan" icon-off="ion-ios-gear-outline" icon-on="ion-ios-gear" href="#/tab/quickscan">
  </ion-tab>
</ion-tabs>

选项卡快速扫描.html

<ion-view view-title="Quick Scan">
  <ion-content class="padding">
    <h2>Welcome to QuickScan</h2>
    <p>
    This is the Ionic starter for tabs-based apps. For other starters and ready-made templates, check out the <a href="http://market.ionic.io/starters" target="_blank">Ionic Market</a>.
    </p>
    <p>
      To edit the content of each tab, edit the corresponding template file in <code>www/templates/</code>. This template is <code>www/templates/tab-dash.html</code>
    </p>
    <p>
    If you need help with your app, join the Ionic Community on the <a href="http://forum.ionicframework.com" target="_blank">Ionic Forum</a>. Make sure to <a href="http://twitter.com/ionicframework" target="_blank">follow us</a> on Twitter to get important updates and announcements for Ionic developers.
    </p>
    <p>
      For help sending push notifications, join the <a href="https://apps.ionic.io/signup" target="_blank">Ionic Platform</a> and check out <a href="http://docs.ionic.io/docs/push-overview" target="_blank">Ionic Push</a>. We also have other services available.
    </p>
  </ion-content>
</ion-view>

首先,将app.js中的语句tab.quickscan更改为以下内容:

.state('tab.quickscan', {
    url: '/quickscan',
    views: {
        'tab-quickscan': {
            templateUrl: 'templates/tab-quickscan.html',
            controller: 'QuickScanCtrl'
        }
    }
})

然后在tabs.html中更改Quick Tab语句:

<ion-tab title="Quick Scan" icon-off="ion-ios-gear-outline" icon-on="ion-ios-gear" href="#/tab/quickscan">
    <!-- name value is defined in `tab.quickscan` statement -->
    <ion-nav-view name='tab-quickscan'></ion-nav-view>
</ion-tab>

ionic tab应用程序使用命名视图(例如 name="tab-dash" , name="tab-account"等)将给定状态的视图呈现到选项卡中。要做到这一点,您需要两件事:

首先,您需要在状态配置中将状态指定为命名视图,如下所示:

.state('tab.quickscan', {
  url: '/quickscan',
  views: {
    'tab-quickscan': {
        templateUrl: 'templates/tab-quickscan.html',
        controller: 'QuickScanCtrl'
    }
  }
})

其次,您需要将ion-nav-view指定为命名视图容器,如下所示:

<ion-tab title="Quick Scan" icon-off="ion-ios-gear-outline" icon-on="ion-ios-gear" ui-sref="tab.quickscan">
  <ion-nav-view name='tab-quickscan'></ion-nav-view>
</ion-tab>
相关文章: