9

我在惰性模块中导入了 ng-bootstrap 的模态库。

@NgModule({imports: [NgbModalModule]})

该库NgbModal在 root 中提供了一项服务。

@Injectable({providedIn: 'root'})
class NgbModal {...}

我将它注入到一个组件中。

constructor(private modal: NgbModal) {}

我开发了一个类扩展。

export class CustomNgbModal extends NgbModal{...}

如何使用 CustomNgbModal 覆盖 NgbModal 类型?

使用模块将是

{provide: NgbModal, useClass: CustomNgbModal}

但是使用提供的根元数据,没有线索。

那么,如何覆盖根目录中提供的模块?

4

1 回答 1

-1

我相信你想要达到的目标可以做到

//module
providers: [
  CustomNgbModal, // so you can inject your custom service
  {provide: NgbModal, useExisting: CustomNgbModal} // to the library would use this service instead of its own
]
于 2020-01-29T16:41:49.883 回答