Angular Material 时间选择器 ngx-material-timepicker 错误 Uncaught (in promise): TypeError: Object(...) is not a function。

3

我使用从这里安装的ngx-material-timepicker时间选择器,使用命令npm install --save ngx-material-timepicker进行安装。 我还安装了依赖项luxon和tslib。 根据npm上的说明:

   import {NgxMaterialTimepickerModule} from 'ngx-material-timepicker';
    @NgModule({
      imports: [NgxMaterialTimepickerModule]
    })

并且在我的HTML文件中

<input [ngxTimepicker]="picker">
<ngx-material-timepicker #picker></ngx-material-timepicker>

但出现错误

core.js:15724 ERROR Error: Uncaught (in promise): TypeError: Object(...) is not a function
TypeError: Object(...) is not a function
    at ngx-material-timepicker.js:231
    at Module../node_modules/ngx-material-timepicker/fesm5/ngx-material-timepicker.js (ngx-material-timepicker.js:238)
    at __webpack_require__ (bootstrap:83)
    at Module../src/app/modules/management/admin/admin.module.ts (admin-routing.module.ts:145)
    at __webpack_require__ (bootstrap:83)
    at $_lazy_route_resource lazy namespace object:34
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391)
    at Object.onInvoke (core.js:17299)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:390)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:150)
    at resolvePromise (zone.js:831)
    at resolvePromise (zone.js:788)
    at zone.js:892
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
    at Object.onInvokeTask (core.js:17290)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:422)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195)
    at drainMicroTaskQueue (zone.js:601)

你安装了哪个版本的ngx-material-timepicker? - Fateme Fazli
最新版本是4.0.1,我认为当运行npm install --save ngx-material-timepicker时会自动安装最新版本。 - Mostafa Bagheri
Angular 的哪个版本? - Robin Webb
1个回答

9

基于 Github 问题此链接,您可以使用版本为 3.3.1 的 "ngx-material-timepicker" 或者如果您正在使用 Angular 8,则可以使用版本为 v4.0.0 或转到 /node_modules/ngx-material-timepicker/fesm5/ngx-material-timepicker.js 并将 ɵɵdefineInjectable 更改为 defineInjectable


1
我使用 Angular 7.3.7,并安装了 Timepicker 版本 3,一切正常,非常感谢。 - Mostafa Bagheri
在 node modules 中编辑某些内容真的是一个明智的想法吗? - ParrapbanzZ
非常感谢,为此浪费了很多时间。 - romal tandel
如果我正在使用Angular 10,应该使用哪个版本的“ngx-material-timepicker”? - Jeet

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接