Sunday, February 16, 2020

How to fix ngx-gallery: Class constructor HammerGestureConfig cannot be invoked without 'new'



When I try to implement ngx-gallery in Angular 8. I found some strange error message:

Class constructor HammerGestureConfig cannot be invoked without 'new'

My first though there's something happen in Angular or ngx-bootsrap version. But, after some debug, definitely it's version problems and we can add same patch solution from github and stackoverflow. This is the full documentation:

  • Go To app.module.ts
  • add this code:

export class CustomHammerConfig extends HammerGestureConfig {
   overrides = {
      pinch: { enable: false },
      rotate: { enable: false },
   };
}
  • apply this patch in your providers app.module.ts
   providers: [
      {
         provide: HAMMER_GESTURE_CONFIGuseClass: CustomHammerConfig
      }
   ],
  • Add Import if necessary 
import { BrowserModuleHAMMER_GESTURE_CONFIGHammerGestureConfig } from '@angular/platform-browser';

Hope it works !!!
Share: