【发布时间】:2020-04-12 02:52:42
【问题描述】:
我正在使用 angular 8 toastr,但我在控制台中收到此错误
ngx-toastr.js:264 Uncaught TypeError: Object(...) is not a function
at ngx-toastr.js:264
at Module../node_modules/ngx-toastr/fesm5/ngx-toastr.js (ngx-toastr.js:271)
at __webpack_require__ (bootstrap:78)
at Module../src/app/app.module.ts (app.component.ts:8)
at __webpack_require__ (bootstrap:78)
at Module../src/main.ts (main.ts:1)
at __webpack_require__ (bootstrap:78)
at Object.0 (main.ts:13)
at __webpack_require__ (bootstrap:78)
at checkDeferredModules (bootstrap:45)
(anonymous) @ ngx-toastr.js:264
./node_modules/ngx-toastr/fesm5/ngx-toastr.js @ ngx-toastr.js:271
__webpack_require__ @ bootstrap:78
./src/app/app.module.ts@app.component.ts:8 webpack_require @bootstrap:78 ./src/main.ts@main.ts:1 webpack_require @bootstrap:78 0@main.ts:13 webpack_require @bootstrap:78 checkDeferredModules @ bootstrap:45 webpackJsonpCallback @ bootstrap:32 (匿名)@ main.js:1 client:148 [WDS] 编译时出现警告。
我已经在命令行中运行了这些
npm install ngx-toastr --save
npm install @angular/animations --save
在我的 app.module.ts 中,我已经包含了这些行
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ToastrModule } from 'ngx-toastr';
imports: [
BrowserModule,
AppRoutingModule,
BrowserAnimationsModule,
ToastrModule.forRoot()
],
我已经在 angular.json 中包含了这个
"node_modules/ngx-toastr/toastr.css"
这是我的 component.ts 文件
import { ToastrService } from 'ngx-toastr';
constract(public toastr: ToastrService){}
ngOnInit() {
this.toastr.success('hello world', 'Success!');
}
当我使用 ng serve 命令运行角度服务器时,它会显示此错误
WARNING in ./node_modules/ngx-toastr/fesm5/ngx-toastr.js 368:198-206
"export 'ɵɵinject' was not found in '@angular/core'
【问题讨论】:
-
您似乎缺少一些引导版本。检查这个 [stackblitz]:stackblitz.com/edit/angular-vb2gpb