Ionic has-header + ionic-side-menus不起作用

时间:2014-05-15 07:42:25

标签: javascript angularjs ionic-framework

嘿大家我一直遇到标题和侧边菜单上的滚动问题。

虽然我已经从这个片段中删除了,但我尝试将class / attr has-header放在几乎所有可能的组合中:

<ion-side-menus>

  <ion-side-menu-content>

    <ion-header-bar class="bar-dark">
      <button class="button icon ion-arrow-left-a" ng-click='back()'></button>
      <h1 class="title">Ionic Shopping Checkout</h1>
      <button class='button icon ion-bag' ng-click='toggleRightSideMenu()'></button>
    </ion-header-bar>

    <ion-purchase></ion-purchase> // custom directive

    <ion-purchase-footer></ion-purchase-footer> // custom directive

  </ion-side-menu-content>

  <ion-side-menu side="right">
    <ion-cart has-header='true' ng-controller='CartController'></ion-cart> // custom directive
  </ion-side-menu>

</ion-side-menus>

此外,即使我将它们嵌套在离子滚动元素中,侧面菜单中的项目的ng-repeat也不会滚动。这可能是一个完全不相关的问题,但是我很好奇是否有人遇到过这个问题。

提前感谢您的所有帮助!

1 个答案:

答案 0 :(得分:6)

如上所述,has-header属性实际上已被删除。但是,has-header类仍然存在。一般来说,你现在不需要管理它们。

我已经设置了一个可以解决所有问题的示例。

http://codepen.io/calendee/pen/Fuejf

关键点与上述评论相同,您的内容需要进入ion-content指令。

这是HTML:

<html ng-app="ionicApp">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">

    <title>Side Menus</title>

    <link href="http://code.ionicframework.com/1.0.0-beta.6/css/ionic.css" rel="stylesheet">
    <script src="http://code.ionicframework.com/1.0.0-beta.6/js/ionic.bundle.js"></script>
  </head>

  <body>

    <div ng-controller="AppController">       
      <ion-nav-view></ion-nav-view>
    </div>

    <script id="app.html" type="text/ng-template">
      <ion-side-menus>

        <ion-side-menu-content>
          <ion-nav-bar class="bar-dark">
            <ion-nav-back-button class="button-icon ion-arrow-left-c">
            </ion-nav-back-button>
          </ion-nav-bar>
          <ion-nav-buttons side="left">
            <button class="button button-icon button-clear ion-navicon" ng-click="toggleLeft()">
            </button>
          </ion-nav-buttons>
          <ion-nav-view name="appContent"></ion-nav-view>
        </ion-side-menu-content> 

        <ion-side-menu side="left">
          <ion-header-bar class="bar-assertive">
            <h1 class="title">Left Menu</h1>
          </ion-header-bar>
          <ion-content>
            <ion-cart ng-controller='CartController'></ion-cart>
          </ion-content>
        </ion-side-menu>
      </ion-side-menus>
    </script>

    <script id="home.html" type="text/ng-template">
      <ion-view title="Ionic Shopping Checkout">
        <ion-content padding="true">
          <ion-purchase></ion-purchase>
        </ion-content>
      </ion-view>
    </script>

    <script id="ionCart.html" type="text/ng-template">
      <div class="list">

        <div class="item" ng-repeat="item in data.items">{{item.label}}</div>
      </div>
    </script>

  </body>
</html>

这是JS:

angular.module('ionicApp', ['ionic'])

.config(function($stateProvider, $urlRouterProvider) {

  $stateProvider
    .state('app', {
      url: "/app",
      abstract: true,
      templateUrl: "app.html"
    })
    .state('app.home', {
      url: "/home",
      views: {
        'appContent' :{
          templateUrl: "home.html",
          controller : "HomeController"
        }
      }
    })

  $urlRouterProvider.otherwise("/app/home");
})

.controller('AppController', function($scope, $ionicSideMenuDelegate) {
  $scope.toggleLeft = function() {
    $ionicSideMenuDelegate.toggleLeft();
  };
})

.controller("HomeController", function($scope) {

})

.controller("CartController", function($scope) {

  $scope.data = {
    items : []
  };

  for(var i = 0; i < 25; i++) {
    $scope.data.items.push({
      id : i,
      label : "Item " + i
    })
  }

})

.directive("ionCart", function() {
  return {
    restrict : "E",
    templateUrl : "ionCart.html"
  }
})

.directive("ionPurchase", function() {
  return {
    restrict : "E",
    template : "<h2>This is Ion Purchase</h2>"
  }
})