Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy load BrowserModule has already been loaded #29906

Closed
soyjuanmedina opened this Issue Apr 15, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@soyjuanmedina
Copy link

soyjuanmedina commented Apr 15, 2019

馃悶 bug report

Affected Package

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

Description

I have two moduels: AppModule and UserModule, and a LoadingComponent use in both.

I try to export it from AppModule to UserModule

@NgModule({
  declarations: [
   ...,
    LoadingComponent
  ],
  imports: [
BrowserModule,,
...
  ],
  providers: [...
  ],
  bootstrap: [AppComponent],
  exports: [
    LoadingComponent
  ]
})
export class AppModule { }

And import in UserModule

@NgModule({
  imports: [
    AppModule,
    CommonModule,
...
  ],
  declarations: [
   ...
  ]
})
export class UserModule { }

But I recibe an error in console:

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.

But as you can see I only import BrowserModule in AppModule, and if I don't import AppModule in UserModule I have an error

Error: Template parse errors:
'loading-component' is not a known element:

  1. If 'loading-component' is an Angular component, then verify that it is part of this module.
@mlc-mlapis

This comment has been minimized.

Copy link

mlc-mlapis commented Apr 15, 2019

@soyjuanmedina ... as described in docs on https://angular.io ... create the third module ... SharedModule and move the LoadingComponent into. Then import the SharedModule to both AppModule and UserModule.

@soyjuanmedina

This comment has been minimized.

Copy link
Author

soyjuanmedina commented Apr 16, 2019

Thanks a lob @mlc-mlapis, it's works.

And sorry if I post this like a bug.... I was looking for a solve but don't find anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can鈥檛 perform that action at this time.