Cannot find name 'HammerManager'

2019-04-25 11:15发布

I am using @angular-2.0.0-rc.5, @angular2-material 2.0.0-alpha.7-4 & Angular-CLI 1.0.0-beta.11-webpack.2

When I try to compile it throws an error, Cannot find name 'HammerManager'. Please see attached screenshot.

Errors

I found some solution for Angular-CLI (non-webpack) version but none for webpack version with.

Any one got this fixed with above setup ?

3条回答
地球回转人心会变
2楼-- · 2019-04-25 11:33

Here is the solution that worked for me ...

  1. npm install hammerjs --save-dev

  2. npm install @types/hammerjs --save-dev

  3. import 'hammerjs'; (in main.ts)

Thanks to @j2L4e & this answer https://github.com/justindujardin/ng2-material/issues/244#issuecomment-241600752

查看更多
Fickle 薄情
3楼-- · 2019-04-25 11:46

You'll need to install the missing typings:

npm install @types/hammerjs --save-dev

Then put a reference to the hammerjs typings into your tsconfig.json:

"types": [
  ...,
  "hammerjs"
]

if that's not enough, also install hammerjs itself via npm:

npm i hammerjs
查看更多
We Are One
4楼-- · 2019-04-25 11:54

While you should use --save-dev when installing the typings, you should use --save when installing hammerjs itself. You will want that installed in production.

查看更多
登录 后发表回答