Vyhledávání na webu

javascript - CHYBA Chyba: Nezachyceno (v příslibu): Chyba: BrowserModule již byl načten : angular 6


Používám více modulů s konceptem lazy loading, ale dostávám následující chybu:

CHYBA Chyba: Nepohlceno (v příslibu): Chyba: BrowserModule již byl načten. Pokud potřebujete přístup k běžným direktivám jako NgIf a NgFor z líně načteného modulu, importujte místo toho CommonModule. Chyba: BrowserModule již byl načten. Pokud potřebujete přístup k běžným direktivám jako NgIf a NgFor z líně načteného modulu, importujte místo toho CommonModule.

app.module.ts

     import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app.routes';
import { CookieModule } from 'ngx-cookie';
/* Modules */
import { SharedModule } from 'shared/shared.module';

/* Components */
import { AppComponent } from './app.component';
/* Models */
import { User } from './shared/models/user';

// /* Services */
import { GlobalLoader } from './core/global-loader';
import { SecurityService } from './shared/services/security.service';
import { BrowserModule } from '@angular/platform-browser';
@NgModule({
   declarations: [
       AppComponent
   ],
   entryComponents: [], // Needed to declare dynamic components
   imports: [      
       BrowserModule,
       AppRoutingModule,
       CookieModule.forRoot(),                          
       SharedModule,
   ],
  exports: [
    SharedModule
  ],
   providers: [SecurityService,
       GlobalLoader,
       User],
   bootstrap: [AppComponent]
})
export class AppModule { }

shared.module.ts

    import { NgModule } from '@angular/core';
// import { FormsModule } from '@angular/forms';
// Small sample component used for dymanic tabs/accordion

/* Components */
import { SampleContent } from './components/sample-content';
import { AccordionCardComponent } from './components/accordion-card/accordion-card.component';
import { BannerComponent } from './components/banner/banner.component';
import { HeaderComponent } from './components/header/header.component';
import { SearchComponent } from './components/search/search.component';
import { TabCardComponent } from './components/tab-card/tab-card.component';
import { TableCardComponent } from './components/table-card/table-card.component';
import { Base64Pipe } from './pipes/base64.pipe';
import { FlexLayoutModule } from '@angular/flex-layout';
import { UXStyleguideModule } from 'ux-angular-styleguide';
import { CommonModule } from '@angular/common';
import { NgxDatatableModule } from '@swimlane/ngx-datatable';
import { HttpClientModule } from '@angular/common/http';
import { FormsModule } from '@angular/forms';
// import { RouterModule } from '@angular/router';
/* Shared */
@NgModule({
    declarations: [
        Base64Pipe,
        SampleContent,
        AccordionCardComponent,
        BannerComponent,
        HeaderComponent,
        SearchComponent,
        TabCardComponent,
        TableCardComponent
    ],
    entryComponents: [], // Needed to declare dynamic components
    imports: [
        HttpClientModule,
        FormsModule,
        CommonModule,
        NgxDatatableModule,
        FlexLayoutModule,
        UXStyleguideModule],
    providers: [],
    exports: [
        HttpClientModule,
        FlexLayoutModule,
        NgxDatatableModule,
        FormsModule,
        CommonModule,
        UXStyleguideModule,
        Base64Pipe,
        SampleContent,
        AccordionCardComponent,
        BannerComponent,
        HeaderComponent,
        SearchComponent,
        TabCardComponent,
        TableCardComponent
    ]
})
export class SharedModule { }

a já jsem nikde neimportoval ten browserModule, ale stále dostávám chybu.

děkuji předem.

Odpověď č. 1

V souboru app.module.ts

Import {BrowserModule} from '@angular/platform-browser';

V Sdíleném modulu:

import { CommonModule } from '@angular/common';

Odeberte BrowserModule ze Shared. Odeberte CommonModule z app.module

Odpověď č. 2

V mém případě jsem zjistil, že problém začíná při importu některého modulu loadChildren v app-routing-module.ts, stále však nevím, jak to upravit.

loadChildren: () => import(`./home/home.module`).then(m => m.HomeModule)

nebo

 loadChildren: './home/home.module#HomeModule'