hammerjs / hammer.js

A javascript library for multi-touch gestures :// You can touch this
http://hammerjs.github.io
MIT License
24.13k stars 2.62k forks source link

Cant use in Angular17 #1296

Open ItaiBarkav opened 10 months ago

ItaiBarkav commented 10 months ago

Hello, I'm trying to use HammerJS in my angular17 project.

I import it in my app.config.ts file:

    importProvidersFrom(HammerModule),

And also I'm my component:

@Component({
  imports: [HammerModule],
  providers: [
    {
      provide: HAMMER_GESTURE_CONFIG,
      useClass: HammerGestureConfig,
    },
  ],
})

I tried this and this not working for me and I get this error in the console: The "swipeleft" event cannot be bound because Hammer.JS is not loaded and no custom loader has been specified

I will thank for any help to solve this problem

lalo-mx commented 9 months ago

Have you tried adding this to providers in app.config.ts?

    {
      provide: HAMMER_GESTURE_CONFIG,
      useClass: HammerGestureConfig,
    },
ovanderzee commented 7 months ago

You should install hammerjs yourself: npm install hammerjs and then get it to load in the app.conifg.ts:

    {
      provide: HAMMER_LOADER,
      useValue: () => import('hammerjs')
    },

I placed the import just before importProvidersFrom(HammerModule). No need to import things in your component.

ion-dev commented 7 months ago

The solution for me was this: https://angular.io/api/platform-browser/HammerModule

  1. In app.component simply import 'hammerjs';
  2. In app.module: import { BrowserModule, HammerModule } from '@angular/platform-browser'; imports: [ BrowserModule, HammerModule,

Everything now works!