【问题标题】:ion-nav-bar button disppears when routing路由时离子导航栏按钮消失
【发布时间】:2015-05-08 03:52:40
【问题描述】:

我有一个带有导航栏和左侧菜单的 Ionic 应用程序。导航栏包含一个扩展左侧菜单的“汉堡包”按钮。侧面菜单包含链接到应用程序不同内容区域的按钮列表。从内容菜单中的项目导航时,应用程序的内容区域会正确更新,并且汉堡图标仍保留在导航栏中。从内容区域中的按钮导航时,汉堡图标将从导航栏中消失。

以下代码演示 (http://codepen.io/FrizziestFuture/pen/pJgvPN)。在这里,页面 A 上的按钮链接到页面 B,但导致汉堡图标消失。侧边菜单链接正常工作。

<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
  <title></title>
  <link href="http://code.ionicframework.com/1.0.0-rc.5/css/ionic.css" rel="stylesheet">
  <script src="http://code.ionicframework.com/1.0.0-rc.5/js/ionic.bundle.js"></script>
</head>

<body ng-app="myApp">
  <ion-side-menus>
    <ion-pane ion-side-menu-content>
      <ion-nav-bar class="bar-balanced">
        <ion-nav-buttons>
          <button menu-toggle="left" class="button button-icon ion-navicon"></button>
        </ion-nav-buttons>
      </ion-nav-bar>
      <ion-nav-view></ion-nav-view>
    </ion-pane>
    <ion-side-menu side="left">
      <ion-content>
        <ion-list>
          <ion-item nav-clear menu-close ui-sref="pageA">Page A</ion-item>
          <ion-item nav-clear menu-close ui-sref="pageB">Page B</ion-item>
        </ion-list>
      </ion-content>
    </ion-side-menu>
  </ion-side-menus>
</body>
<script id="templates/pageA.html" type="text/ng-template">
  <ion-view>
    <ion-content>
      <h1>Page A</h1>
      <button ui-sref="pageB">Go to Page B</button>
    </ion-content>
  </ion-view>
</script>
<script id="templates/pageB.html" type="text/ng-template">
  <ion-view>
    <ion-content>
      <h1>Page B</h1>
    </ion-content>
  </ion-view>
</script>
<script src="myApp.js"></script>
</html>

angular.module("myApp", ["ionic"])
.config(function ($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise("/pageA");

    $stateProvider
    .state("pageA", {
        url: "/pageA",
        templateUrl: "templates/pageA.html"
    })
    .state("pageB", {
        url: "/pageB",
        templateUrl: "templates/pageB.html"
    });
});

【问题讨论】:

标签: angularjs ionic


【解决方案1】:

天啊。我花了这么多时间才找到它,所以我必须在这里更明确地分享它。

所有功劳归 Stefan van de Vooren 以及他在此处提供的链接。

按钮隐藏在子视图默认情况下,菜单切换按钮将 仅出现在根级别的侧菜单页面上。导航到孩子 视图将隐藏菜单切换按钮。它们可以在 通过设置的 enable-menu-with-back-views 属性设置子页面 ionSideMenus 指令为 true。

&lt;ion-side-menus enable-menu-with-back-views="true"&gt;

来源由 Stefan van de Vooren 提供:http://ionicframework.com/docs/api/directive/menuToggle/

【讨论】:

    【解决方案2】:

    对于 Ionic 2 和 3,代码如下所示

    <ion-menu persistent="true">
    

    ion-menu 属性“persistent”如果不添加则默认为 false。

    【讨论】:

      猜你喜欢
      • 2014-10-01
      • 2018-09-26
      • 1970-01-01
      • 2016-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多