Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant use in Angular17 #1296

Open
ItaiBarkav opened this issue Jan 20, 2024 · 3 comments
Open

Cant use in Angular17 #1296

ItaiBarkav opened this issue Jan 20, 2024 · 3 comments

Comments

@ItaiBarkav
Copy link

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
Copy link

lalo-mx commented Feb 14, 2024

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

    {
      provide: HAMMER_GESTURE_CONFIG,
      useClass: HammerGestureConfig,
    },

@ovanderzee
Copy link

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
Copy link

ion-dev commented Apr 10, 2024

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants