Angular-'找不到HammerJS' [英] Angular - 'Could not find HammerJS'

查看:79
本文介绍了Angular-'找不到HammerJS'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个简单的角度项目中,尝试将Material Design导入到我的项目中,但是某些组件无法正常工作,并且控制台警告说:

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:

找不到HammerJS.某些Angular Material组件可能无法正常工作.

我已经安装了hammerjs,还安装了@angular/material.我该如何解决这个问题?

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





可能值得注意的是,如果您安装了hammerjs并且组件仍无法正确呈现,请确保您使用的是angular material 组件,而不是使用materialize-css的html元素课程. 如果您使用 materialize-css 而不是您需要分别将其添加到您的项目中.

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.

推荐答案

在您的package.json文件中,将其添加到dependencies

In your package.json file add this to dependencies

"hammerjs":"^ 2.0.8",

"hammerjs": "^2.0.8",

或者如果您想使用另一种自动方式,只需在根项目文件夹中输入npm i hammerjs --save(或npm i hammerjs@2.0.8 --save,因为2.0.8是当今的最新版本),然后然后进行测试,如果问题仍然存在,请尝试删除node_modules文件夹,然后通过运行npm install将其重新安装在根项目文件夹中,这将检查dependencies( where hammerjs驻留),devDependencies ...,保存在package.json文件中.

Or if you want an alternative automatic way just you can type npm i hammerjs --save (or npm i hammerjs@2.0.8 --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.

也要在您的polyfills.ts中使用(如果没有,建议使用一个)

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

导入'hammerjs/hammer';

import 'hammerjs/hammer';

因此,在执行有角度的应用程序时会发现它,因为polyfills.ts本身是由导入调用的(通常情况下,您可以检查它)main.ts中角度应用程序的入口点.

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.

这篇关于Angular-'找不到HammerJS'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆