问题
The code below uses segments from ionic 3. docs show the use of ngSwitch, ngModel. but I would like to simply swipe on the segment and switch to another segment tab. How can I achieve this?
I am not interested in swiping the tabs at the top but by swiping on the content i would like to change the segment tab.
<ion-content padding>
  <div>
    <ion-segment [(ngModel)]="abc">
      <ion-segment-button value="Segment1">
        Segment Title
      </ion-segment-button>
      <ion-segment-button value="segment2">
        Segment Title
      </ion-segment-button>
    </ion-segment>
  </div>
  <div [ngSwitch]="abc">
    <ion-list *ngSwitchCase="'segment2'" class="list-fixed">
      <ion-item>
        <ion-thumbnail item-start>
          <img src="assets/imgs/1.jpg">
        </ion-thumbnail>
        <h2>List Item 1</h2>
        <p>List Item Subtitle</p>
        <button ion-button clear item-end>View</button>
      </ion-item>
    </ion-list>
    <ion-list *ngSwitchCase="'segment1'" class="list-fixed">
      <ion-item>
        <ion-thumbnail item-start>
          <img src="assets/imgs/3.png">
        </ion-thumbnail>
        <h2>List Item Title 1</h2>
        <p>Subheading</p>
        <button ion-button clear item-end>View</button>
      </ion-item>
    </ion-list>
  </div>
    回答1:
My Solution was to Add :
.html file
//Add below code where you would like to detect the swipe from users input
// When user makes a swipe simply check and do the switch between Tabs.
(pan)='swipeEvent($event)' 
.ts file
pages: string = "pageA";
swipeEvent($e) {
    console.log($e.deltaX+", "+$e.deltaY);
    if($e.deltaX > 0){
      console.log("Swipe from Left to Right");
      this.pages = "pageB";
    }else{
      console.log("Swipe from Right to Left");
      this.pages = "pageA";
    }
}
Thanks to David's Comment
来源:https://stackoverflow.com/questions/46973693/swipe-through-segment-tabs-ionic-3