首页 > 解决方案 > 未捕获的类型错误:core_1.style 不是函数

问题描述

我将代码从 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 很陌生。先感谢您。

标签: javascriptangulartypescriptangular7

解决方案


看起来问题实际上出ng2-material-dropdown在他们使用style@angular/corehttps://v4.angular.io/api/core/style)导入的函数的旧版本上,该函数在 Angular 4 中已弃用并移至@angular/animationshttps://v4.angular.io/api/core/style ) /angular.io/api/animations/style

在 0.9.0 版本中,ng2-material-dropdown 库添加了对 Angular 版本 5 和 6 的支持,因此我建议您也更新该库。目前有 0.10.1 版本可用。


推荐阅读