Commit 822439f
fix(core):
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 #44966ViewContainerRef.createComponent should consult module injector when custom one is provided (#44966)1 parent 1b91e10 commit 822439f
File tree
2 files changed
+75
-12
lines changed- packages/core
- src/linker
- test/acceptance
2 files changed
+75
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
345 | 365 | | |
346 | 366 | | |
347 | 367 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
1411 | 1412 | | |
1412 | 1413 | | |
1413 | 1414 | | |
1414 | | - | |
| 1415 | + | |
1415 | 1416 | | |
1416 | 1417 | | |
1417 | 1418 | | |
| |||
1424 | 1425 | | |
1425 | 1426 | | |
1426 | 1427 | | |
1427 | | - | |
| 1428 | + | |
1428 | 1429 | | |
1429 | 1430 | | |
1430 | 1431 | | |
1431 | 1432 | | |
1432 | 1433 | | |
1433 | | - | |
| 1434 | + | |
1434 | 1435 | | |
1435 | 1436 | | |
1436 | 1437 | | |
1437 | 1438 | | |
1438 | 1439 | | |
1439 | | - | |
| 1440 | + | |
1440 | 1441 | | |
1441 | 1442 | | |
1442 | 1443 | | |
| |||
1454 | 1455 | | |
1455 | 1456 | | |
1456 | 1457 | | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
| 1499 | + | |
1457 | 1500 | | |
1458 | 1501 | | |
1459 | 1502 | | |
| |||
1489 | 1532 | | |
1490 | 1533 | | |
1491 | 1534 | | |
1492 | | - | |
1493 | | - | |
| 1535 | + | |
| 1536 | + | |
1494 | 1537 | | |
1495 | 1538 | | |
1496 | 1539 | | |
| |||
0 commit comments