angularjs - 如何在没有新模板的情况下在 Ionic 选项卡中呈现内容,而只需像在 Bootstrap 中切换选项卡

标签 angularjs ionic-framework angular-ui-router

我们正在构建一个包含三个选项卡的模板。这些选项卡应该像在这个例子中一样工作:https://getbootstrap.com/javascript/#tabs-examples

我们只想在选项卡中切换内容。我们如何在不需要新模板的情况下做到这一点?

我们的细节模板是这样的:

<ion-view view-title="{{item.summary.name}}">
  <ion-nav-buttons side="left">
    <button class="button button-icon button-clear ion-navicon" menu-toggle="left"></button>
  </ion-nav-buttons>


  <div class="bar bar-subheader bar-assertive">
    <ion-tabs class="tabs-background-assertive tabs-color-light">
      <ion-tab title="Summary">
        <ion-nav-view name="summary" ></ion-nav-view>
      </ion-tab>

      <ion-tab title="Ingridents">
        <ion-nav-view name="ingdts"></ion-nav-view>
      </ion-tab>

      <ion-tab title="Videos">
        <ion-nav-view name="video"></ion-nav-view>
      </ion-tab>

    </ion-tabs>
  </div>

</ion-view>

我们试过了,https://stackoverflow.com/a/31506520/170445但它不工作。

最佳答案

在您的 Controller 中有某种​​类型的对象来控制可见性:

 $scope.pageFlow = {
    summary: true,
    ingts: false,
    video: false
 }

然后在您查看时只显示或隐藏 div。您还可以创建一个作用域方法来处理控件,但不是必需的。需要注意的一件事是 ion-tabs 在 ion-content 之外,但在 ion-view 内
<ion-view view-title="{{item.summary.name}}">
 <ion-nav-buttons side="left">
    <button class="button button-icon button-clear ion-navicon" menu-toggle="left"></button>
 </ion-nav-buttons>
 <ion-content padding="true" scroll="true" class="has-header">
    <div ng-if="pageFlow.summary">
        Summary Goes Here
    </div>
    <div ng-if="pageFlow.ingdts">
        Ingredients Goes Here
    </div>
    <div ng-if="pageFlow.video">
        Video Goes Here
    </div>
 </ion-content>
 <ion-tabs class="tabs-background-assertive tabs-color-light">>
    <ion-tab title="Summary" on-select="pageFlow.summary = true; pageFlow.video = false; pageFlow.ingdts = false">
    </ion-tab>
    <ion-tab title="Ingridents" on-select="pageFlow.ingdts = true; pageFlow.video = false; pageFlow.other = false">
    </ion-tab>
    <ion-tab title="Videos" on-select="pageFlow.video = true; pageFlow.ingdts = false; pageFlow.other = false">
    </ion-tab>
 </ion-tabs></ion-view>

我还应该注意,您现在只需要一个 Controller 来查看 View ,因为所有内容都在一个内容页面内。

关于angularjs - 如何在没有新模板的情况下在 Ionic 选项卡中呈现内容,而只需像在 Bootstrap 中切换选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38013347/

相关文章:

javascript - UI-Router 状态 : How to make app. 使用 $rootScope.$ 在缩小安全上运行

javascript - Angularjs 不呈现 $rootscope 数据

javascript - 将 angularjs 指令添加到 native html 元素(输入文本、div、span 等)?

javascript - Angular 添加按钮不起作用

angularjs - 监视 AngularJS 中的过滤事件 - 延迟加载图像

ionic-framework - 当我尝试在移动设备上安装 ionic4 生成的 app-debug.apk 时出错

android - ionic : unable to build app after installing `cordova-plugin-fcm`

javascript - HTML5 pushState Clash w/Angular UI-Router URL 路由

angularjs - Angular UI、Bootstrap 导航栏折叠和 Javascript

java - 从 cordova 插件 java 文件访问本地存储或 SQLite