ngx-bootstrap: Modal component causes 'Error: Token must be defined!' for AoT runtime

I use shared module to define Modals and share it with different parts of the app

import { NgModule, ModuleWithProviders } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';

import { ModalModule } from 'ng2-bootstrap';


@NgModule({
  imports: [
      CommonModule,
      ModalModule.forRoot()
  ],
  exports: [
      CommonModule,
      FormsModule,
      ModalModule
  ]
})
export class SharedModule {
  static forRoot(): ModuleWithProviders {
    return {
      ngModule: SharedModule
    };
  }
}

JIT compilation and runtime work fine. AoT compilation works fine but during runtime I got this error:

EXCEPTION: Uncaught (in promise): Error: Token must be defined!
Error: Token must be defined!

The issue disappears when I remove modal component div (bsModal) from template.

I use Angular 2.4.1, ng2-bootstrap 1.1.16-11

Here is a repo with steps to reproduce: https://github.com/irsick/ng2-bootstrap-bsModals-issue

Probably it’s related to #986

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 41 (34 by maintainers)

Most upvoted comments

your PR published as v1.2.6

I will take a look asap