Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular - 'Could not find HammerJS'

I'm working on a simple angular project where I am trying to import Material Design into my project but some of the components aren't working properly and a console warning says:

Could not find HammerJS. Certain Angular Material components may not work correctly.

I have hammerjs installed and also @angular/material. How do I resolve this issue?



Sidenote

It may be worth noting that if you have hammerjs installed and your components are still not rendering correctly to make sure you are using angular material components and not html elements with materialize-css classes. If you are using materialize-css instead of angular material, you will need to add it to your project separately.

like image 498
Danoram Avatar asked Dec 25 '16 15:12

Danoram


People also ask

What is Hammer JS?

Hammer. js is a small, standalone javascript-library that enables multitouch gestures like swipe, pinch, rotate, tap and drag on mobile devices. This is a utility module and you won't need it unless you are a developer or another module asks you to install it.


2 Answers

In your package.json file add this to dependencies

"hammerjs": "^2.0.8",

Or if you want an alternative automatic way just you can type npm i hammerjs --save (or npm i [email protected] --save if you want, since 2.0.8 is the latest version nowdays) in your root project folder and test then, if the problem still occurring try to delete the node_modules folder and reinstall it in the root project folder also by running npm install which will check the dependencies (where hammerjs resides), devDependencies ..., in package.json file and install them.

Also in your polyfills.ts (recommended to have a one if you have not)

import 'hammerjs/hammer';

Thus, it would be found while your angular app is executed since polyfills.ts itself is called by import (in a normal case, else you can check it) in main.ts which is the angular apps' entry point.

like image 56
SeleM Avatar answered Sep 24 '22 04:09

SeleM


Install hammerjs

  • with npm

    npm install --save hammerjs 
  • (or) with yarn

    yarn add hammerjs 

Then import hammerjs on your app's entry point (e.g. src/main.ts).

import 'hammerjs'; 



like image 31
All Іѕ Vаиітy Avatar answered Sep 24 '22 04:09

All Іѕ Vаиітy