Pizzicato
Pizzicato

Reputation: 1621

How to create a standalone custom library that uses a non-stanalone third party library in Angular?

I have a custom library that uses another third-party library (ngx-bootstrap) which is not a collection of standalone components, services, etc... and requires importing Modules. This custom library is working well exporting a module that imports the needed modules from ngx-bootstrap.

I'd like to know if it's possible to make my library fully standalone, or I need keep exporting that module.

Upvotes: 1

Views: 213

Answers (1)

alx lark
alx lark

Reputation: 864

In my case when I try solve similar case ( standalone components and ngx-bootsrap) it was fixed via importProvidersFrom.

My prev code like

import { ModalModule } from 'ngx-bootstrap/modal';

@NgModule({
...
  imports: [
    ModalModule.forRoot(),
...

Now works as

import { importProvidersFrom } from '@angular/core';
import { ModalModule } from 'ngx-bootstrap/modal';

...
  providers: [
...
    importProvidersFrom(
      ModalModule.forRoot()
        )
...

and fixes issues like

object.bsmodalservice_factory nullinjectorerror: nullinjectorerror: no provider for rendererfactory2!

more info https://angular.io/guide/standalone-components#configuring-dependency-injection and https://angular.io/api/core/importProvidersFrom

Upvotes: -1

Related Questions