替换已弃用的 ViewContainerRef.parentinjector

Plo*_*hie 4 angular

升级到 Angular 7 后,我进入parentInjector is deprecated: No replacement了我的代码。由于这显然已被弃用,为什么没有可用的更新,或者 Angular 团队只是错过了在文档中添加它?

我正在使用注入器在 dom 中动态添加组件。

const factory = this.cfr.resolveComponentFactory(modalClass);
const ref = factory.create(this.vcr.parentInjector);
Run Code Online (Sandbox Code Playgroud)

Rea*_*lar 6

由于这显然已被弃用,为什么没有可用的更新,或者 Angular 团队只是错过了在文档中添加它?

这是一个 API 错误,应该是一个私有成员。依赖注入器没有层次结构。您无法从Angular 中任何地方的注入器获取父注入器。

我正在使用注入器动态添加组件 dom。

你应该this.vcr.injector改用。如果此更改破坏了您的源代码,则需要更改您的源代码。

GitHub 问题:https : //github.com/angular/angular/pull/25174

请求弃用 API:https : //github.com/angular/angular/pull/25092#discussion_r205181787