kolkov / ngx-gallery

A simple responsive native gallery component for Angular 8+.
https://ngx-gallery.kolkov.ru/
MIT License
115 stars 56 forks source link

Using ngx-gallery component in lazy module is not working in Angular 13 #88

Closed Vikas4790 closed 2 years ago

Vikas4790 commented 2 years ago

Using ngx-gallery works fine in a non lazy module, but throws 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. when trying to access the component in a lazy module. Is anyone else facing the same issue?

It can be easily reproduced in a new angular13 project with "@kolkov/ngx-gallery": "^2.0.0" package version. Sample code of lazy loaded module -

@NgModule({
  declarations: [Component2Component],
  imports: [
    NgxGalleryModule,
    RouterModule.forChild([{ path: "", component: Component2Component }]),
  ],
})
export class Module2Module {}

And then loading Module2Module lazily in app module like below throws the error when navigating to http://localhost:4200/component2-

RouterModule.forRoot([
      ...
      {
        path: "component2",
        loadChildren: () =>
          import("./module2/module2.module").then((m) => m.Module2Module),
      },
    ]),

I feel this is related to the BrowserAnimationsModule getting imported alongside NgxGalleryModule when we add NgxGalleryModule to the imports: [...] of Module2Module. Since main app.module has already an import for BrowserModule so angular compiler throws up the error message stating that BrowserModule has already been loaded. Though I am not sure how to fix this if this is the issue.

randallmeeker commented 2 years ago

This is the same in angular 9, rolling back version to version 1.2.3 fixed for me

Vikas4790 commented 2 years ago

But my application is on Angular13 now and ngx-gallery's version 2.0.0 is compatible with Angular13.

randallmeeker commented 2 years ago

sure, was not saying this is not an issue, was just adding context. For me, it was 1.2.4 that broke my app.

mnesser commented 2 years ago

Same issue using lazy modules (v2.0.0). Works fine using v1.2.3.

khvnkay commented 2 years ago

any update ?

andrejm7 commented 2 years ago

I had the same problem... I had to go back to the previous version...

andrejm7 commented 2 years ago

@kolkov can u help? I went back to angular 12

andrejm7 commented 2 years ago

@lukasmatta @Simbaclaws

andrejm7 commented 2 years ago

I did the test here.. can you generate a new version without the IMPORT BrowserAnimationsModule ?

andrejm7 commented 2 years ago

Please.. confirm pull request

andrejm7 commented 2 years ago

with version 2.0.1 this problem has been fixed. thanks.

Vikas4790 commented 2 years ago

This issue is resolved after the update 2.0.1. Marking it as closed. Thanks for the update @andrejm7 @kolkov .