import { Injectable } from '@angular/core' ; @ Injectable ( ) export class SwipeService { private _swipeCoord ? : [ number , number ] ; private _swipeTime ? : number ; param { TouchEvent } e param { string } when returns { number } description swipe ( e , when ) { const coord = [ e . changedTouches [ 0 ] . pageX , e . changedTouches [ 0 ] . pageY ] ; const time = new Date ( ) . getTime ( ) ; if ( when === 'start' ) { this . _swipeCoord = coord ; this . _swipeTime = time ; } else if ( when === 'end' ) { const direction = [ coord [ 0 ] - this . _swipeCoord [ 0 ] , coord [ 1 ] - this . _swipeCoord [ 1 ] ] ; const duration = time - this . _swipeTime ; if ( duration < 1000 && Math . abs ( direction [ 1 ] ) < Math . abs ( direction [ 0 ] ) && Math . abs ( direction [ 0 ] ) > 30 ) { return direction [ 0 ] < 0 ? 1 : - 1 ; } } return 0 ; } }