https://github.com/angular/angular
Revision 822439fdddfca316ac826569042efab460e67b50 authored by Andrew Kushnir on 03 February 2022, 23:19:05 UTC, committed by Dylan Hunn on 08 February 2022, 17:57:20 UTC
Before Ivy, it was only possible to call the `ViewContainerRef.createComponent` function with the ComponentFactory as the first argument. An instance of a `ComponentFactory` resolved via `ComponentFactoryResolver` contained a reference to an `NgModule` where the component is declared. As a result, the component maintained a DI connection with the module injector tree (by retrieving an instance of `NgModuleRef` internally), even when the custom injector was provided (we try to find a token in a custom injector first and consult module injector after that).

With Ivy, we expanded the `ViewContainerRef.createComponent` function API to support direct references to the Component classes without going through the factory resolution step. As a result, there was no connection to the NgModule that declares the component. Thus, if you provide a custom injector, this is the only injector that is taken into account.

This commit updates the logic for the factory-less case to try retrieving an instance of an `NgModuleRef` using the DI tree which `ViewContainerRef` belongs to. The `NgModuleRef` instance is then used to get a hold of a module injector tree. This brings the factory-less and factory-based logic to more consistent state.

Closes #44897.

PR Close #44966
1 parent 1b91e10
History
Tip revision: 822439fdddfca316ac826569042efab460e67b50 authored by Andrew Kushnir on 03 February 2022, 23:19:05 UTC
fix(core): `ViewContainerRef.createComponent` should consult module injector when custom one is provided (#44966)
Tip revision: 822439f
File Mode Size
.circleci
.devcontainer
.github
.husky
.ng-dev
.vscode
.yarn
aio
devtools
docs
goldens
integration
modules
packages
scripts
third_party
tools
.bazelignore -rw-r--r-- 2.8 KB
.bazelrc -rw-r--r-- 6.7 KB
.bazelversion -rw-r--r-- 6 bytes
.clang-format -rw-r--r-- 73 bytes
.editorconfig -rw-r--r-- 245 bytes
.gitattributes -rw-r--r-- 240 bytes
.gitignore -rw-r--r-- 797 bytes
.gitmessage -rw-r--r-- 7.2 KB
.mailmap -rw-r--r-- 51 bytes
.npmrc -rw-r--r-- 21 bytes
.nvmrc -rw-r--r-- 8 bytes
.prettierrc -rw-r--r-- 157 bytes
.pullapprove.yml -rw-r--r-- 48.2 KB
.yarnrc -rw-r--r-- 130 bytes
BUILD.bazel -rw-r--r-- 2.0 KB
CHANGELOG.md -rw-r--r-- 994.7 KB
CODE_OF_CONDUCT.md -rw-r--r-- 1.1 KB
CONTRIBUTING.md -rw-r--r-- 15.9 KB
LICENSE -rw-r--r-- 1.1 KB
README.md -rw-r--r-- 4.7 KB
WORKSPACE -rw-r--r-- 3.2 KB
browser-providers.conf.js -rw-r--r-- 1.8 KB
gulpfile.js -rw-r--r-- 631 bytes
karma-js.conf.js -rw-r--r-- 6.0 KB
package.json -rw-r--r-- 9.4 KB
renovate.json -rw-r--r-- 2.7 KB
test-events.js -rw-r--r-- 259 bytes
tsconfig-tslint.json -rw-r--r-- 171 bytes
tslint.json -rw-r--r-- 5.4 KB
yarn.lock -rw-r--r-- 696.8 KB
yarn.lock.readme.md -rw-r--r-- 1.3 KB

README.md

back to top