ngx-popper
ngx-popper copied to clipboard
NgxPopperModule.forRoot should be only used with AppModule
to my understanding, the module.forRoot should be only used in bootstrapped module, and any options passed by forRoot should be inherit into any other module.
but now ngx-popper need to use forRoot on every module and repeatly set the options. the options didn't inherit from the bootstrapped module.
So I don't know if this is the design or something wrong?
just checked the source, you are using the provider to set the default options, and provider is module indepentend, so by your design this is the correct result.
you might need to change from plain string provide: 'popperDefaults' to
export const POPPER_DEFAULTS = new InjectionToken<PopperContentOptions>('popperDefaults');
public static forRoot(popperBaseOptions: PopperContentOptions = {}): ModuleWithProviders {
return {ngModule: NgxPopperModule, providers: [{provide: POPPER_DEFAULTS, useValue: popperBaseOptions}]};
}
this will make forRoot actually forRoot.
no, the problem is not the InjectionToken, because in module you write:
providers: [
{
provide: 'popperDefaults', useValue: {}
}]
this will make any module import use a empty option, to use a default option, we need to use forRoot in every module import to set the options, and also because of these lines, you all options can not be inherited into children modules of AppModule.
@steve3d , thanks for bringing this up, sorry for the late reply, ill look into your PR
when can we expect the new version?
I just stumbled across this, when upgrading a library of mine which uses NgxPopper.
I was previously using NgxPopper 6.0.7 and everything was fine.
But now with v 7.0.0 I got an error saying NullInjectorError: No provider for popperDefaults! which I had to solve by adding the forRoot to a secondary module (luckily it was only 1).
@steve3d if you're interested I'm about to fork this project because I noticed that MrFrankel has not been answering lately, I need this and I don't want the extra forRoot and I need to make everything work with Angular 9 for a project I'm working on...
@steve3d just released [email protected] with some improvements, like this and upgrade to @popperjs/core 2