Uncaught TypeError: core_1.style is not a function

Uncaught TypeError: core_1.style is not a function

我将代码从 Angular 4 转换为 Angular 7 并成功编译。 但是当我尝试 运行 它时,在 broser 的控制台中它给出了以下错误。

Uncaught TypeError: core_1.style is not a function
at Object.<anonymous> (ng2-dropdown.bundle.js:435)
at __webpack_require__ (ng2-dropdown.bundle.js:30)
at Object.<anonymous> (ng2-dropdown.bundle.js:121)
at __webpack_require__ (ng2-dropdown.bundle.js:30)
at Object.<anonymous> (ng2-dropdown.bundle.js:65)
at __webpack_require__ (ng2-dropdown.bundle.js:30)
at ng2-dropdown.bundle.js:50
at ng2-dropdown.bundle.js:53
at webpackUniversalModuleDefinition (ng2-dropdown.bundle.js:3)
at Object../node_modules/ng2-tag-input/node_modules/ng2-material-dropdown/dist/ng2-dropdown.bundle.js (ng2-dropdown.bundle.js:10)

有人能指出我为什么会收到此错误吗?我对 Angular 很陌生。在此先感谢您。

看起来问题实际上出在旧版本的 ng2-material-dropdown 上,他们使用从 @angular/core (https://v4.angular.io/api/core/style) which was deprecated in Angular 4 and moved to @angular/animations (https://angular.io/api/animations/style)[=16 导入的 style 函数=]

在 0.9.0 版本中 ng2-material-dropdown library added support for Angular version 5 & 6 所以我建议你也更新那个库。目前有0.10.1版本可用。

如果这里的所有解决方案都不能解决您的问题,您可以尝试删除node_modules文件夹,然后运行npm installyarn重新安装所有依赖项,这也是我的解决方案。