加载惰性模块在app.module中给出错误错误:未定义不是函数

时间:2019-06-09 14:33:17

标签: angular

这是我的App.module.ts 文件。我正在尝试加载 AuthModule ,但这给出了错误,即Undefined不是函数。这意味着模块是尚未加载。请告诉我如何导入该模块。任何其他建议将不胜感激。

import { BrowserModule } from '@angular/platform-browser';
import { DataTablesModule } from 'angular-datatables';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule } from '@angular/core';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';
import { FooterComponent } from './footer/footer.component';
import { IconComponent } from './components/icon/icon.component';
import { BreadComponent } from './components/bread/bread.component';
import { NavbarComponent } from './components/navbar/navbar.component';
import {FoooterComponent} from './components/foooter/footer.component';
import { SidebarComponent } from './components/sidebar/sidebar.component';
import { AppRoutingModule } from './app-routing.module';
import { AuthInterceptor } from './auth/auth-interceptor';
import { ErrorInterceptor } from './error-interceptor';
import { ErrorComponent } from './error/error.component';
import { AngularMaterialModule } from './angular-material.module';
import { EventsModule } from './events/events.module';
import { MDBBootstrapModule } from 'angular-bootstrap-md';
import { ChatComponent } from './chat/chat.component';
import { AdminComponent } from './admin/admin.component';
import { DatatableslibraryComponent  } from './admin/datatables/datatables.component';
import { EventsComponent } from './admin/events/events.component';
import { UsersComponent } from './users/users.component';
import { FormsModule } from '@angular/forms';
import { MatTableModule } from '@angular/material';
import { MatIconModule } from '@angular/material'
import { MatPaginatorModule } from '@angular/material';
import { MatSortModule } from '@angular/material';
import { MatDialogModule } from '@angular/material';
import {AuthModule} from './auth/auth.module';
import { JwSocialButtonsModule } from 'jw-angular-social-buttons';

@NgModule({
  declarations: [
    AppComponent,
    HeaderComponent,
    FooterComponent,
    ErrorComponent,
    ChatComponent,
    AdminComponent,
    UsersComponent,
    NavbarComponent,
    SidebarComponent,
    FoooterComponent,
    IconComponent,
    BreadComponent,
    DatatableslibraryComponent ,
    EventsComponent

  ],
  imports: [
    AuthModule,
    BrowserModule,
    FormsModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    HttpClientModule,
    AngularMaterialModule,
    EventsModule,
    MDBBootstrapModule.forRoot(),
    JwSocialButtonsModule,
     DataTablesModule ,
     MatTableModule,
     MatIconModule ,
     MatPaginatorModule,
     MatSortModule,
     MatDialogModule

  ],
  providers: [
    { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true },
    { provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true }
  ],
  bootstrap: [AppComponent],
  entryComponents: [ErrorComponent]
})
export class AppModule {}

我试图将其导入到我的主模块文件中。问题仅在于AuthModule,否则代码运行正常,因此请告诉我如何导入Authmodule。

1 个答案:

答案 0 :(得分:0)

如果您是延迟加载模块,则无需再导入到AppModule

所以您的代码将是这样

imports: [
    BrowserModule,
    FormsModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    HttpClientModule,
    AngularMaterialModule,
    EventsModule,
    MDBBootstrapModule.forRoot(),
    JwSocialButtonsModule,
     DataTablesModule ,
     MatTableModule,
     MatIconModule ,
     MatPaginatorModule,
     MatSortModule,
     MatDialogModule

  ],