1

I run into a simple... but ennoying issue with ModalModule:

I am using: https://github.com/tinesoft/generator-ngx-library to share components between projects.

here:

1) yeoman the lib

2) in the lib import ngx-bootstrap

3) write some code on the existing component ‘LibComponent’. Actually, i copy/pasted the exemple code of modals on ngxboot website.

4) gulp build

5) Try to execute the already defined demo in the library. (inside demo folder).

I have this error:

ERROR Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[LibComponent -> BsModalService]:

Thx you in advance for any advice... I'm a bit lost :D.

I did all normal stuff like:

here is the code of the Lib Module:

    @NgModule({
      imports: [
        CommonModule,
        FormsModule,
        ModalModule.forRoot(),
        ReactiveFormsModule,
        ButtonsModule.forRoot()
      ],
      exports: [LibComponent],
      declarations: [LibComponent]
    })
    export class LibModule {
      static forRoot(): ModuleWithProviders {
        return {
          ngModule: LibModule,
          providers: [LibService]
        };
      }
    }

here is the code of the component:

      import { Component, TemplateRef } from '@angular/core';
      import { BsModalService } from 'ngx-bootstrap/modal';
      import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';

      @Component({
        selector: 'zca-component',
        templateUrl: './lib.component.html'
      })
      export class LibComponent {
        modalRef: BsModalRef;
        constructor(private modalService: BsModalService) { }

        openModal(template: TemplateRef<any>) {
          this.modalRef = this.modalService.show(template);
        }
      }
user3178486
  • 321
  • 6
  • 17
  • So ngx-bootstrap source code is included in resulting bundle, so you get duplicated `BsModalService` declaration in App So question is: how is exclude ngx-bootstrap source code, from your libs bundle – valorkin Jan 15 '18 at 15:50
  • 1
    Valorkin show me this solution: https://www.npmjs.com/package/ng-packagr. It seems to be clearer and way easier. – user3178486 Jan 15 '18 at 17:28
  • 1
    Add this comment as an answer please, and mark this question as answered :) – valorkin Jan 15 '18 at 17:38

0 Answers0