fegyi001 / mangol

Maps created with Angular & OpenLayers using Material design
http://188.166.116.137/mangol/
98 stars 47 forks source link

BrowserModule is re-imported #31

Closed Ghostbird closed 4 years ago

Ghostbird commented 4 years ago

When I try to use Mangol in a lazy loaded module I run into this issue:

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.

The re-import is non-fatal when it does not happen in a lazy loaded module. However, in this case <mangol> cannot be used in the template. of a lazy loaded module component. So as a workaround:

  1. Move the import to the root module of the app.
  2. Add the MangolComponent as entryComponent to the root module of the app.
  3. In the constructor of the component where you need the MangolComponent: Dynamically create a new MangolComponent using ComponentFactoryResolver and add it to the ViewContainerRef of the component.

However, this is quite an ugly workaround, as far as I know, non-root Angular modules should never import the BrowserModule.

Cosmocat commented 4 years ago

However, this is quite an ugly workaround, as far as I know, non-root Angular modules should never import the BrowserModule.

@fegyi001 BrowserModule, BrowserAnimationsModule need to be removed from mangol.module.ts imports

fegyi001 commented 4 years ago

@Ghostbird thanks for the issue, @Cosmocat thanks for the fix. New version will be out soon.

fegyi001 commented 4 years ago

Fixed in 9.1.10-0.2