ionic-framework - 有没有办法读取 Ion-Segment 值以将它们传递给 Ion-Fab 以根据 SwitchCase 运行不同的功能?

标签 ionic-framework ionic3

我目前有一个带有两个 switchCases 的 Ion-Segment。即管理与市场。但是,我想包含一个 FAB 按钮,以根据用户所在的 SwitchCase 运行不同的功能。

我已经尝试将 FAB 放置在 SwitchCase 选项中,但是 FAB 似乎在页面上滚动而不是停留在页面上。

晶圆厂应针对不同的开关盒运行不同的功能。

//段代码

    <ion-header>
        <ion-segment [(ngModel)]="options" color="grey">
            <ion-segment-button value="Management">
                Management
            </ion-segment-button>
            <ion-segment-button value="Market">
                Crop Market
            </ion-segment-button>
        </ion-segment>
    </ion-header>

//CODE FOR IMPLEMENTATION OF THE SEGMENT

    <ion-content>
    <div [ngSwitch]="options" class="management-class"> //FIRST SWITCH CASE
    <div *ngSwitchCase="'Management'">
    <//MANAGEMENT CONTENT FOR THIS SWITCH CASE>
    </div>
    </div>

    <div [ngSwitch]="options" class="management-class">//SECOND SWITCH CASE
    <div *ngSwitchCase="'Market'">
    <//MARKET CONTENT FOR THIS SWITCH CASE>
    </div>
    </div>

    //This is the ion-fab button to that switches functions based on the users current switch case.

    <ion-fab right bottom>
        <button *ngIf="this.options=Market" ion-fab (click)="addToMarket()" color="primary" mini><img src="assets/imgs/add1.png"></button>
        <button *ngIf="this.options=Management" ion-fab (click)="plantNew()" color="primary" mini><img src="assets/imgs/add1.png"></button>
    </ion-fab>

</ion-content>

最佳答案

在您的片段上使用 ionChange 事件,例如:

<ion-segment (ionChange)="segmentChanged($event)">
    <ion-segment-button value="friends">
      <ion-label>Friends</ion-label>
    </ion-segment-button>
    <ion-segment-button value="enemies">
      <ion-label>Enemies</ion-label>
    </ion-segment-button>
  </ion-segment>

在你的 component.ts 中

segmentChanged(e){
    console.log(e.detail.value)
    this.segmentValue = e.detail.value;
}

改变你的值(value)观:

<ion-fab right bottom>
        <button *ngIf="segmentValue == 'friends'" ion-fab (click)="addToMarket()" color="primary" mini><img src="assets/imgs/add1.png"></button>
        <button *ngIf="segmentValue == 'enemies'" ion-fab (click)="plantNew()" color="primary" mini><img src="assets/imgs/add1.png"></button>
    </ion-fab>

关于ionic-framework - 有没有办法读取 Ion-Segment 值以将它们传递给 Ion-Fab 以根据 SwitchCase 运行不同的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57802047/

相关文章:

php - 运行 ionic 应用程序时出现无法加载资源:net::ERR_CONNECTION_REFUSED

android - Ionic3 将给定日期更改为所需格式

angular - 获取 RC0 中的当前页面/ View 名称返回 “t”

angular - Observable<any> 不可分配给类型 Observable<any>

ionic-framework - 找不到错误 io.branch.referral.InstallListener 类崩溃 Ionic v5

angular - 同一项目中的 Ionic 2 和 Angular 2

javascript - ionic 2 : "black screen" after modal close

javascript - 范围变量未从状态父 Controller 继承到子 Controller

html - ionic ionic radio css :Selected

node.js - Ionic - 运行时错误 : Object(. ..) 不是函数