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

NgbRTL isn't exported from @ng-bootstrap/ng-bootstrap #4403

Closed
snakamura opened this issue Oct 19, 2022 · 13 comments
Closed

NgbRTL isn't exported from @ng-bootstrap/ng-bootstrap #4403

snakamura opened this issue Oct 19, 2022 · 13 comments

Comments

@snakamura
Copy link

Bug description:

After upgrading ng-bootstrap from 13.0.0 to 13.1.0, I found that NgbTooltip now took NgbRTL. So I injected NgbRTL and passed it to the constructor of NgbTooltip. When I did this, I imported NgbRTL from @ng-bootstrap/ng-bootstrap/util/rtl directly, because it wasn't exported from @ng-bootstrap/ng-bootstrap.

Now, while building the Angular app, I encountered this error.

./dist/util/fesm2020/util.mjs:16:0-60 - Error: Module not found: Error: Package path ./util/rtl is not exported from package /Users/project/node_modules/@ng-bootstrap/ng-bootstrap (see exports field in /Users/project/node_modules/@ng-bootstrap/ng-bootstrap/package.json)

I guess this can be fixed by exporting NgbRTL from @ng-bootstrap/ng-bootstrap. Or, am I missing something?

Versions of Angular, ng-bootstrap and Bootstrap:

Angular: 14.2.6
ng-bootstrap: 13.1.0
Bootstrap: 5.2.2

@maxokorokov
Copy link
Member

NgbRTL is a private service at the moment, you shouldn't use it

@snakamura
Copy link
Author

@maxokorokov Thank you for your answer. Does it mean that we shouldn't create NgTooltip programmatically? We have a directive that will create NgbTooltip depending on the situation dynamically. So we instantiate NgbTooltip programmatically. Now that the constructor of NgbTooltip takes NgbRTL, we can no longer instantiate it if we shouldn't use NgbRTL. Can I ask what your suggestion is in this kind of situations?

@maxokorokov
Copy link
Member

maxokorokov commented Oct 25, 2022

I wouldn't instantiate directives like this dynamically exactly because of the issue you're facing now... constructors are not meant to be called manually...

Would this solve your issues with Angular 15? → angular/angular#46868

I'll see if we can make NgbRTL public meanwhile

@snakamura
Copy link
Author

@maxokorokov Thank you for your suggestion. Yes, I think angular/angular#46868 will help. With it, we would no longer need to instantiate NgbTooltip directly.

Even though creating an instance isn't recommended, it'd be great if you can make NgbRTL public.

@yildiraymeric
Copy link

We have a custom directive which extends NgbTooltip and adds additional functionality that we need to it. Now we can not compile our code due to NgbRTL not being public.

Please make NgbRTL public.

@murarinayak
Copy link

I have the same issue for NgbTooltip as well as NgbDropdown.
I have extended these 2 components with additional functionality. Now this doesn't work, after updating.

Please make NgbRTL public.

@jakobpinggera
Copy link

We got the same issue as we are extending NgbTooltip. Making NgbRTL public would resolve this.

@Wycza
Copy link

Wycza commented Dec 7, 2022

Hello, I have the same issue. I can't extend NgbPopover because NgbRTL is not exported. To make it work with Angular 15 now I just copied NgbRTL.ts file into my project and then used it as below:

constructor(
    [...]
    private rtl: NgbRTL,
    [...]
  ) {
    super(_elRef, rtl as any, _render, injector, viewContainerRef, config, ngZone, _document, changeRef, applicationRef);
    }

maxokorokov added a commit to maxokorokov/ng-bootstrap that referenced this issue Dec 12, 2022
@maxokorokov
Copy link
Member

While we still do not recommend extending our components, this would probably help → #4443. WDYT?

@maxokorokov maxokorokov added this to the 14.0.1 milestone Dec 12, 2022
@snakamura
Copy link
Author

@maxokorokov Oh, it looks great to me. Thank you.

We're moving toward hostDirectives based on your suggestion, by the way. It seems working fine with Angular 15 and ng-bootstrap 14.0.0.

@hudsontavares
Copy link

hudsontavares commented Jun 11, 2023

For people stumbling upon this problem where upgrading to version 14.0.0 isn't an immediate solution, two suggestions:

a) If you're injecting properties, use Angular 14+ inject() instead of declaring a constructor

import { inject } from '@angular/core';
import { NgbPopover } from '@ng-bootstrap/ng-bootstrap';

import { MyInjectable } from './my/injectable';

export MyExtendedClass extends NgbPopover {
private readonly myInjectable = inject(MyInjectable);

b) Any property initialization could be done on the ngOnInit instead of the constructor.

Using that, you don't need to override the constructor and avoid the ngbRTL problem.

@maxokorokov
Copy link
Member

@hudsontavares, this should have been fixed in 14.0.17f2146d

@hudsontavares
Copy link

hudsontavares commented Jun 12, 2023

@hudsontavares, this should have been fixed in 14.0.17f2146d

Yes, @maxokorokov, thanks for pointing it out - I was shedding some alternative light for people in projects where upgrading to the fixed version isn't an immediate option and existing components are already extending some ng-bootstrap stuff. You don't need to redeclare a constructor in the subclass using the approaches above, so the original, ngbRTL-enabled constructor will continue working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants