Ionic Not Loading Tab页面

时间:2016-04-25 23:20:25

标签: javascript angularjs tabs ionic-framework

我一直在为这个问题抨击我几天,我知道这是一种过于简单化的事情,我早就应该注意到了,但对于我的生活,我无法弄明白。

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

我从Ionic“标签”模板开始新鲜,并且只更改了必要的内容(或者我相信)。

感谢任何帮助。

app.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');

});

controllers.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");
});

tabs.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>

制表quickscan.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>

2 个答案:

答案 0 :(得分:1)

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

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

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

<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>

答案 1 :(得分:0)

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>