0

Importing NgClockPickerLib Module in Lazy loaded module which is creating error : Error: Uncaught (in promise): Error: BrowserModule has already been loaded. If you need access to common directives such as NgIf and NgFor from a lazy loaded module, import CommonModule instead.

This is because NgClockPickerLib Module internally imports BrowserAnimations Module.

How to use NgClockPickerLib Module in lazy loaded module ??

app module

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { SharedDataService } from './services/shared-data.service';


@NgModule({
  declarations: [
    AppComponent,
    ...
  ],
  imports: [
    BrowserModule,  
    AppRoutingModule,
    ...
  ],
  providers: [
    SharedDataService,
    ...
  ],
  exports: [
   
  ],
  bootstrap: [AppComponent]
})

app routing module

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule, Routes } from '@angular/router';

const routes: Routes = [
  { path: 'journalling', loadChildren: './Journalling/modules/journalling.module#JournallingModule' }
];

@NgModule({
  imports: [
    CommonModule,
    RouterModule.forRoot(routes)
  ],
  declarations: [

  ],
  exports: [RouterModule]
})
export class AppRoutingModule { }

journalling module

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { JournallingRoutingModule } from './journalling-routing.module';
import { NgClockPickerLibModule } from 'ng-clock-picker-lib';


@NgModule({
  imports: [
    CommonModule,
    JournallingRoutingModule,
    NgClockPickerLibModule
  ],
  declarations: [ 
  ],
  providers: [
  ]
})
export class JournallingModule { }

enter image description here

Aryan
  • 3,338
  • 4
  • 18
  • 43
  • looks like a NgClockPickerLibModule bug. authour shouldn't be importing BrowserModule as well as BrowserAnimationsModule – Andrei Sep 28 '20 at 12:18
  • so whats the solution ? How can i use the NgClockPickerLibModule in lazy loaded module ? – Heena Aggarwal Sep 28 '20 at 13:44
  • can it be done like importing NgClockPickerLibModule in AppModule and exporting it and making it accessible to JournallingModule ? – Heena Aggarwal Sep 28 '20 at 14:04
  • Or can we eagerly load the JournallingModule (it contains only 2 components and few 3rd party modules) . will this solve the problem and how to eagerly load a module ? – Heena Aggarwal Sep 29 '20 at 04:50

0 Answers0