0

When i upgrade my app to Angular 16, hammerjs config not working with the config below

main.ts

@Injectable()
export class MyHammerConfig extends HammerGestureConfig {
  overrides = <any>{
    swipe: { direction: Hammer.DIRECTION_ALL },
  };
}

if (environment.production) {
  enableProdMode();
}

const routes: Routes = [
  {
    path: "",
    component: GestureSliderComponent,
  },
];

bootstrapApplication(AppComponent, {
  providers: [
    provideRouter(routes),
    provideAnimations(),
    { provide: HAMMER_GESTURE_CONFIG, useClass: MyHammerConfig },
  ],
}).catch((err: any) =>
  console.error("Application Boostrapping Error... ", err)
);

GestureSliderComponent html

<div class="slider-section" (swipe)="onSwipe($event)"></div>

GestureSliderComponent ts

onSwipeRight(event, data) {
  console.log("event => ", event);
}
4
  • Maybe you have to add HammerModule to our @NgModule imports in your standalone component. Commented May 12, 2023 at 14:00
  • i tried but didn't work Commented May 15, 2023 at 12:27
  • 1
    See issue github.com/angular/angular/issues/50447 . As a workaround you might want to import HammerModule as a provider.
    – eight
    Commented Jun 19, 2023 at 15:55
  • I forgot to mention that i found the solution (importProvidersFrom(HammerModule)), thanks Commented Jun 19, 2023 at 17:47

0