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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't set config #393

Closed
MarcManhart opened this issue Jun 10, 2021 · 10 comments · Fixed by #583
Closed

Can't set config #393

MarcManhart opened this issue Jun 10, 2021 · 10 comments · Fixed by #583

Comments

@MarcManhart
Copy link

MarcManhart commented Jun 10, 2021

My template looks like that:

<mat-dialog-content>
  <gallery id="bilderGallery"></gallery>
</mat-dialog-content>

my Component like that:

public galleryConf: GalleryConfig = {
    thumb: false
  };

//...

ngOnInit() {
    let imagesToRender = this.data.bilder.map((bild: any) => {
         //...  (already working)
    });

    this.galleryRef = this.gallery.ref('bilderGallery');
    this.galleryRef.setConfig(this.galleryConf); // <-- seems not to do anything
    this.galleryRef.load(imagesToRender);
  }

//...

Unfortunately the config get ignored. The image loading works but calling setConfig(...) or even writing <gallery id="bilderGallery" [thumbs]=false></gallery> won't changing anything. The gallery is loaded always with the default configuration.

What am Im doing wrong?
Thx

@MurhafSousli
Copy link
Owner

MurhafSousli commented Jun 11, 2021

Looking at your code, it should work.. can you reproduce it in a stackblitz?

@EchopixUser
Copy link

What if you try to set the config in the ref() function?
this.galleryRef = this.gallery.ref('bilderGallery', this.galleryConf);

@EchopixUser
Copy link

EchopixUser commented Sep 17, 2021

Also @MurhafSousli if you try to load config in the GalleryModule using forRoot method (you call it withConfig) it will not work. I believe the reason for it not working is following:

In your gallery.service.ts you are injecting the config with GALLERY_CONFIG. However, the service itself is provided in root, and gets created sooner than the module, where the config value is resolved. Therefor this line will always only use defaultConfig since config will always be undefined.

@MurhafSousli
Copy link
Owner

@EchopixUser you can inject the token in the root module to set the default config.. regarding withConfig function I am not sure, I haven't tested it after upgrading the service with providedIn feature

@EchopixUser
Copy link

I am providing it in my gallery module which amongst other things sets up your gallery module and hence the issue arises. I don't want to provide it in root, I have a modular architecture and the modules are sealed and independent.

@AlexType
Copy link

ngAfterViewInit(): void {
    this.galleryRef.setConfig(this.config);
}

в ngOnInit не успевает

@MurhafSousli
Copy link
Owner

@EchopixUser Providing a token in the root won't effect the modular structure, and won't add the plugin size to your main script if that what concerns you.

@EchopixUser
Copy link

EchopixUser commented Sep 24, 2021

I have a monorepo with multiple projects, so what concerns me is that I need to provide token with same value in every project. I would rather encapsulate it in my Module that would setup the config in one place for all my apps.

Anyway the withConfig does not work because of of the hierarchy of providers you now have.

@MurhafSousli
Copy link
Owner

@EchopixUser Can you think of a solution?

@EchopixUser
Copy link

@EchopixUser Can you think of a solution?

Don't provide gallery in root by default. let the user chose the providing point.

@MurhafSousli MurhafSousli linked a pull request Dec 23, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants