错误 无法读取未定义的 ngx-toastr 的属性'push'



在我的应用程序中,我正在尝试集成Toast

作为其中的一部分,我初始化了package.json和angular.json。到目前为止,应用程序工作正常。但当我初始化app.module.ts

应用程序模块.ts

  imports: [
    BrowserModule,
    AppRoutingModule,
    HttpClientModule,
    FormsModule,
    ReactiveFormsModule,
    ToastrModule.forRoot({
      timeOut: 1000,
      positionClass: 'toast-bottom-right'
    })
  ],
export class AppModule { }

我得到以下错误。

@import must precede all other statements (besides @charset)
WARNING in Entry point 'ngx-toastr' contains deep imports into 'C:/Users/angular-frontend/node_modules/@angular/compiler/src/core'. This is probably not a problem, but may cause the compilation of entry points to be out of order.
ERROR in Cannot read property 'push' of undefined

我已经通过解决了这个问题

ng update @angular/cli @angular/core --allow-dirty

使用@NgModule装饰器装饰您的导入:

import {ToastrModule} from 'ngx-toastr';
@NgModule({
  imports: [
    BrowserModule,
    AppRoutingModule,
    HttpClientModule,
    FormsModule,
    ReactiveFormsModule,
    ToastrModule.forRoot({
      timeOut: 1000,
      positionClass: 'toast-bottom-right'
    })
  ],
})
export class AppModule {}

请参阅https://angular.io/guide/architecture-modules

最新更新