angularnavigationswipe-gesture

What is the best way to implement swipe navigation in Angular 2?


I'm new to Angular 2 and am looking for a way to implement a good tab touch swipe navigation for mobile users with a swipe transition to the next tab view.

So far I've found a package called angular2-useful-swiper although am not to keen on using it as I end up initializing my components early even though they are not in view.

Does anyone know a good way to implement a tab swipe based navigation for Angular 2? Any feedback will be greatly appreciated. : )


Solution

  • You can use HammerJS to implement for touch actions, You can follow this plunker for example.

    Include hammer.js file

    <script src="https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.js"></script>
    

    or

    npm install hammerjs --save
    

    For browser touch support with hammerjs, include

     <script src="http://cdn.rawgit.com/hammerjs/touchemulator/master/touch-emulator.js"></script>
    <script>
    

    Import in app.module.ts

    import { HammerGestureConfig, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
    
    export class MyHammerConfig extends HammerGestureConfig  {
      overrides = <any>{
        'swipe': {velocity: 0.4, threshold: 20} // override default settings
      }
    }
    
    @NgModule({
      imports: [BrowserModule],
      declarations: [AppComponent],
      bootstrap: [AppComponent],
      providers: [{ 
        provide: HAMMER_GESTURE_CONFIG, 
        useClass: MyHammerConfig 
      }] // use our custom hammerjs config
    })
    

    plunker link for example

    To implement tabs angular2-material is a good place to start, follow this link