Redirect to homepage when click tow time on the tabs


#1

hi community
i want to click two time on the tab then redirect to homepage
any suggestion


#2

Hello,

maybe this is what you looking for Ionic - Double Tap?

Otherwise you can maybe implement it with a counter and reset it to our needs, for example a timer.

Best regards, anna-liebt


#3

thanks for replay
i try this solution but i get this errore

core.js:1449 ERROR Error: Uncaught (in promise): TypeError: Cannot read property ‘addEventListener’ of undefined
TypeError: Cannot read property ‘addEventListener’ of undefined


#4

Hello,
this error mean usually that whatever from whatever.addEventListner is not or not at runtime available. Take a look to whatever and clarify why is nothing assigned to whatever.

Best regards, anna-liebt


#5

hi this is my code

tabsreserve.ts

import { Component,ViewChild,ElementRef,OnDestroy ,AfterViewInit } from '@angular/core';
import { IonicPage, NavController, NavParams,Tab,Events,Tabs  } from 'ionic-angular';
import {Gesture} from 'ionic-angular/gestures/gesture';
 
/*import { ReserverPage } from '../reserver/reserver';
import { LacartePage } from '../lacarte/lacarte';
import { AProposPage } from '../a-propos/a-propos';
import { LocaliserPage } from '../localiser/localiser';
import { TelPage } from '../tel/tel';*/



@IonicPage()
@Component({
  selector: 'page-tabsreserve',
  templateUrl: 'tabsreserve.html',
})
export class TabsreservePage {
  @ViewChild('mainTabs') mainTabs: Tabs;
  @ViewChild('element') el: ElementRef;
  tab:Tabs;
  reserverRoot = 'ReserverPage'
  lacarteRoot = 'LacartePage'
  aProposRoot = 'AProposPage'
  localiserRoot = 'LocaliserPage'
  telRoot = 'TelPage'
  tab2Params:any ; 
  page:number = 0;
  selectedIndex: string;
  private pressGesture: Gesture;
   // tab2Params = { id: 1, url:"http",cord:"cord" };
  constructor(public navCtrl: NavController,public navParams: NavParams, public events: Events) {
    this.tab = this.navCtrl.parent;
 }
 public ngAfterViewInit(): void {

  this.pressGesture = new Gesture(this.el.nativeElement);

  this.pressGesture.listen();
  this.pressGesture.on('doubletap', (e:Event) => {

    console.log("guster",e.type);
    // or ... this.yourMethod(e);


    
  });

}

public ngOnDestroy(): void {
  this.pressGesture.destroy();
}

   ngOnInit() {
    // Let's navigate from TabsPage to Page1
    this.tab2Params=this.navParams.get('localdata');
    
 }


tabsreserve.html


<ion-tabs  #mainTabs (tap)="tapped()"  >
<ion-tab #element [root]="reserverRoot" tabTitle="Reserver" tabIcon="ios-calendar" [rootParams]="tab2Params"  ></ion-tab>
<ion-tab [root]="lacarteRoot" tabTitle="Lacarte" tabIcon="ios-restaurant" [rootParams]="tab2Params"  ></ion-tab>
<ion-tab [root]="aProposRoot" tabTitle="A propos" tabIcon="ios-information-circle" [rootParams]="tab2Params"  ></ion-tab>
<ion-tab [root]="localiserRoot" tabTitle="Localiser" tabIcon="ios-pin" [rootParams]="tab2Params" ></ion-tab>
<ion-tab [root]="telRoot" tabTitle="Tel" tabIcon="ios-phone-portrait-outline" [rootParams]="tab2Params" ></ion-tab>
</ion-tabs>


#6

what is wrong ???..


#7

Hello,

maybe your @ViewChild(‘element’) el: ElementRef; is the problem. The original post fetch a div as ElementRef which is okay. ion-tab is not a ElementRef to a native element.

Best regards, anna-liebt


#8

thanks for reply
so how can add double click in the tab ?


#9

hello,

I didn’t test it, because I am not using ion-tab, but documentation says it is a navcontroller. If NavController doesn’t work and google/bing deliever no results, then you can maybe use your fetched mainTabs and compare it with getselected(), that is that tab you wanna use.

Best regards, anna-liebt