@angular/core 14.0.0-next.4 → 14.0.0-next.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/fesm2015/core.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Angular v14.0.0-next.4
2
+ * @license Angular v14.0.0-next.5
3
3
  * (c) 2010-2022 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
@@ -1211,6 +1211,7 @@ const DECLARATION_LCONTAINER = 17;
1211
1211
  const PREORDER_HOOK_FLAGS = 18;
1212
1212
  const QUERIES = 19;
1213
1213
  const ID = 20;
1214
+ const EMBEDDED_VIEW_INJECTOR = 21;
1214
1215
  /**
1215
1216
  * Size of LView's header. Necessary to adjust for it when setting slots.
1216
1217
  *
@@ -1218,7 +1219,7 @@ const ID = 20;
1218
1219
  * instruction index into `LView` index. All other indexes should be in the `LView` index space and
1219
1220
  * there should be no need to refer to `HEADER_OFFSET` anywhere else.
1220
1221
  */
1221
- const HEADER_OFFSET = 21;
1222
+ const HEADER_OFFSET = 22;
1222
1223
  /**
1223
1224
  * Converts `TViewType` into human readable text.
1224
1225
  * Make sure this matches with `TViewType`
@@ -2468,7 +2469,7 @@ function incrementInitPhaseFlags(lView, initPhase) {
2468
2469
  assertNotEqual(initPhase, 3 /* InitPhaseCompleted */, 'Init hooks phase should not be incremented after all init hooks have been run.');
2469
2470
  let flags = lView[FLAGS];
2470
2471
  if ((flags & 3 /* InitPhaseStateMask */) === initPhase) {
2471
- flags &= 2047 /* IndexWithinInitPhaseReset */;
2472
+ flags &= 4095 /* IndexWithinInitPhaseReset */;
2472
2473
  flags += 1 /* InitPhaseStateIncrementer */;
2473
2474
  lView[FLAGS] = flags;
2474
2475
  }
@@ -2532,12 +2533,12 @@ function callHook(currentView, initPhase, arr, i) {
2532
2533
  const directiveIndex = isInitHook ? -arr[i] : arr[i];
2533
2534
  const directive = currentView[directiveIndex];
2534
2535
  if (isInitHook) {
2535
- const indexWithintInitPhase = currentView[FLAGS] >> 11 /* IndexWithinInitPhaseShift */;
2536
+ const indexWithintInitPhase = currentView[FLAGS] >> 12 /* IndexWithinInitPhaseShift */;
2536
2537
  // The init phase state must be always checked here as it may have been recursively updated.
2537
2538
  if (indexWithintInitPhase <
2538
2539
  (currentView[PREORDER_HOOK_FLAGS] >> 16 /* NumberOfInitHooksCalledShift */) &&
2539
2540
  (currentView[FLAGS] & 3 /* InitPhaseStateMask */) === initPhase) {
2540
- currentView[FLAGS] += 2048 /* IndexWithinInitPhaseIncrementer */;
2541
+ currentView[FLAGS] += 4096 /* IndexWithinInitPhaseIncrementer */;
2541
2542
  profiler(4 /* LifecycleHookStart */, directive, hook);
2542
2543
  try {
2543
2544
  hook.call(directive);
@@ -3098,6 +3099,8 @@ const BLOOM_MASK = BLOOM_SIZE - 1;
3098
3099
  const BLOOM_BUCKET_BITS = 5;
3099
3100
  /** Counter used to generate unique IDs for directives. */
3100
3101
  let nextNgElementId = 0;
3102
+ /** Value used when something wasn't found by an injector. */
3103
+ const NOT_FOUND = {};
3101
3104
  /**
3102
3105
  * Registers this directive as present in its node's injector by flipping the directive's
3103
3106
  * corresponding bit in the injector's bloom filter.
@@ -3209,23 +3212,7 @@ function getParentInjectorLocation(tNode, lView) {
3209
3212
  // `LView` hierarchy and look for it. If we walk of the top, that means that there is no parent
3210
3213
  // `NodeInjector`.
3211
3214
  while (lViewCursor !== null) {
3212
- // First determine the `parentTNode` location. The parent pointer differs based on `TView.type`.
3213
- const tView = lViewCursor[TVIEW];
3214
- const tViewType = tView.type;
3215
- if (tViewType === 2 /* Embedded */) {
3216
- ngDevMode &&
3217
- assertDefined(tView.declTNode, 'Embedded TNodes should have declaration parents.');
3218
- parentTNode = tView.declTNode;
3219
- }
3220
- else if (tViewType === 1 /* Component */) {
3221
- // Components don't have `TView.declTNode` because each instance of component could be
3222
- // inserted in different location, hence `TView.declTNode` is meaningless.
3223
- parentTNode = lViewCursor[T_HOST];
3224
- }
3225
- else {
3226
- ngDevMode && assertEqual(tView.type, 0 /* Root */, 'Root type expected');
3227
- parentTNode = null;
3228
- }
3215
+ parentTNode = getTNodeFromLView(lViewCursor);
3229
3216
  if (parentTNode === null) {
3230
3217
  // If we have no parent, than we are done.
3231
3218
  return NO_PARENT_INJECTOR;
@@ -3386,93 +3373,116 @@ function lookupTokenUsingModuleInjector(lView, token, flags, notFoundValue) {
3386
3373
  */
3387
3374
  function getOrCreateInjectable(tNode, lView, token, flags = InjectFlags.Default, notFoundValue) {
3388
3375
  if (tNode !== null) {
3389
- const bloomHash = bloomHashBitOrFactory(token);
3390
- // If the ID stored here is a function, this is a special object like ElementRef or TemplateRef
3391
- // so just call the factory function to create it.
3392
- if (typeof bloomHash === 'function') {
3393
- if (!enterDI(lView, tNode, flags)) {
3394
- // Failed to enter DI, try module injector instead. If a token is injected with the @Host
3395
- // flag, the module injector is not searched for that token in Ivy.
3396
- return (flags & InjectFlags.Host) ?
3397
- notFoundValueOrThrow(notFoundValue, token, flags) :
3398
- lookupTokenUsingModuleInjector(lView, token, flags, notFoundValue);
3376
+ // If the view or any of its ancestors have an embedded
3377
+ // view injector, we have to look it up there first.
3378
+ if (lView[FLAGS] & 2048 /* HasEmbeddedViewInjector */) {
3379
+ const embeddedInjectorValue = lookupTokenUsingEmbeddedInjector(tNode, lView, token, flags, NOT_FOUND);
3380
+ if (embeddedInjectorValue !== NOT_FOUND) {
3381
+ return embeddedInjectorValue;
3399
3382
  }
3400
- try {
3401
- const value = bloomHash(flags);
3402
- if (value == null && !(flags & InjectFlags.Optional)) {
3403
- throwProviderNotFoundError(token);
3404
- }
3405
- else {
3406
- return value;
3407
- }
3383
+ }
3384
+ // Otherwise try the node injector.
3385
+ const value = lookupTokenUsingNodeInjector(tNode, lView, token, flags, NOT_FOUND);
3386
+ if (value !== NOT_FOUND) {
3387
+ return value;
3388
+ }
3389
+ }
3390
+ // Finally, fall back to the module injector.
3391
+ return lookupTokenUsingModuleInjector(lView, token, flags, notFoundValue);
3392
+ }
3393
+ /**
3394
+ * Returns the value associated to the given token from the node injector.
3395
+ *
3396
+ * @param tNode The Node where the search for the injector should start
3397
+ * @param lView The `LView` that contains the `tNode`
3398
+ * @param token The token to look for
3399
+ * @param flags Injection flags
3400
+ * @param notFoundValue The value to return when the injection flags is `InjectFlags.Optional`
3401
+ * @returns the value from the injector, `null` when not found, or `notFoundValue` if provided
3402
+ */
3403
+ function lookupTokenUsingNodeInjector(tNode, lView, token, flags, notFoundValue) {
3404
+ const bloomHash = bloomHashBitOrFactory(token);
3405
+ // If the ID stored here is a function, this is a special object like ElementRef or TemplateRef
3406
+ // so just call the factory function to create it.
3407
+ if (typeof bloomHash === 'function') {
3408
+ if (!enterDI(lView, tNode, flags)) {
3409
+ // Failed to enter DI, try module injector instead. If a token is injected with the @Host
3410
+ // flag, the module injector is not searched for that token in Ivy.
3411
+ return (flags & InjectFlags.Host) ?
3412
+ notFoundValueOrThrow(notFoundValue, token, flags) :
3413
+ lookupTokenUsingModuleInjector(lView, token, flags, notFoundValue);
3414
+ }
3415
+ try {
3416
+ const value = bloomHash(flags);
3417
+ if (value == null && !(flags & InjectFlags.Optional)) {
3418
+ throwProviderNotFoundError(token);
3408
3419
  }
3409
- finally {
3410
- leaveDI();
3411
- }
3412
- }
3413
- else if (typeof bloomHash === 'number') {
3414
- // A reference to the previous injector TView that was found while climbing the element
3415
- // injector tree. This is used to know if viewProviders can be accessed on the current
3416
- // injector.
3417
- let previousTView = null;
3418
- let injectorIndex = getInjectorIndex(tNode, lView);
3419
- let parentLocation = NO_PARENT_INJECTOR;
3420
- let hostTElementNode = flags & InjectFlags.Host ? lView[DECLARATION_COMPONENT_VIEW][T_HOST] : null;
3421
- // If we should skip this injector, or if there is no injector on this node, start by
3422
- // searching the parent injector.
3423
- if (injectorIndex === -1 || flags & InjectFlags.SkipSelf) {
3424
- parentLocation = injectorIndex === -1 ? getParentInjectorLocation(tNode, lView) :
3425
- lView[injectorIndex + 8 /* PARENT */];
3426
- if (parentLocation === NO_PARENT_INJECTOR || !shouldSearchParent(flags, false)) {
3427
- injectorIndex = -1;
3428
- }
3429
- else {
3430
- previousTView = lView[TVIEW];
3431
- injectorIndex = getParentInjectorIndex(parentLocation);
3432
- lView = getParentInjectorView(parentLocation, lView);
3433
- }
3420
+ else {
3421
+ return value;
3434
3422
  }
3435
- // Traverse up the injector tree until we find a potential match or until we know there
3436
- // *isn't* a match.
3437
- while (injectorIndex !== -1) {
3438
- ngDevMode && assertNodeInjector(lView, injectorIndex);
3439
- // Check the current injector. If it matches, see if it contains token.
3440
- const tView = lView[TVIEW];
3441
- ngDevMode &&
3442
- assertTNodeForLView(tView.data[injectorIndex + 8 /* TNODE */], lView);
3443
- if (bloomHasToken(bloomHash, injectorIndex, tView.data)) {
3444
- // At this point, we have an injector which *may* contain the token, so we step through
3445
- // the providers and directives associated with the injector's corresponding node to get
3446
- // the instance.
3447
- const instance = searchTokensOnInjector(injectorIndex, lView, token, previousTView, flags, hostTElementNode);
3448
- if (instance !== NOT_FOUND) {
3449
- return instance;
3450
- }
3451
- }
3452
- parentLocation = lView[injectorIndex + 8 /* PARENT */];
3453
- if (parentLocation !== NO_PARENT_INJECTOR &&
3454
- shouldSearchParent(flags, lView[TVIEW].data[injectorIndex + 8 /* TNODE */] === hostTElementNode) &&
3455
- bloomHasToken(bloomHash, injectorIndex, lView)) {
3456
- // The def wasn't found anywhere on this node, so it was a false positive.
3457
- // Traverse up the tree and continue searching.
3458
- previousTView = tView;
3459
- injectorIndex = getParentInjectorIndex(parentLocation);
3460
- lView = getParentInjectorView(parentLocation, lView);
3461
- }
3462
- else {
3463
- // If we should not search parent OR If the ancestor bloom filter value does not have the
3464
- // bit corresponding to the directive we can give up on traversing up to find the specific
3465
- // injector.
3466
- injectorIndex = -1;
3423
+ }
3424
+ finally {
3425
+ leaveDI();
3426
+ }
3427
+ }
3428
+ else if (typeof bloomHash === 'number') {
3429
+ // A reference to the previous injector TView that was found while climbing the element
3430
+ // injector tree. This is used to know if viewProviders can be accessed on the current
3431
+ // injector.
3432
+ let previousTView = null;
3433
+ let injectorIndex = getInjectorIndex(tNode, lView);
3434
+ let parentLocation = NO_PARENT_INJECTOR;
3435
+ let hostTElementNode = flags & InjectFlags.Host ? lView[DECLARATION_COMPONENT_VIEW][T_HOST] : null;
3436
+ // If we should skip this injector, or if there is no injector on this node, start by
3437
+ // searching the parent injector.
3438
+ if (injectorIndex === -1 || flags & InjectFlags.SkipSelf) {
3439
+ parentLocation = injectorIndex === -1 ? getParentInjectorLocation(tNode, lView) :
3440
+ lView[injectorIndex + 8 /* PARENT */];
3441
+ if (parentLocation === NO_PARENT_INJECTOR || !shouldSearchParent(flags, false)) {
3442
+ injectorIndex = -1;
3443
+ }
3444
+ else {
3445
+ previousTView = lView[TVIEW];
3446
+ injectorIndex = getParentInjectorIndex(parentLocation);
3447
+ lView = getParentInjectorView(parentLocation, lView);
3448
+ }
3449
+ }
3450
+ // Traverse up the injector tree until we find a potential match or until we know there
3451
+ // *isn't* a match.
3452
+ while (injectorIndex !== -1) {
3453
+ ngDevMode && assertNodeInjector(lView, injectorIndex);
3454
+ // Check the current injector. If it matches, see if it contains token.
3455
+ const tView = lView[TVIEW];
3456
+ ngDevMode &&
3457
+ assertTNodeForLView(tView.data[injectorIndex + 8 /* TNODE */], lView);
3458
+ if (bloomHasToken(bloomHash, injectorIndex, tView.data)) {
3459
+ // At this point, we have an injector which *may* contain the token, so we step through
3460
+ // the providers and directives associated with the injector's corresponding node to get
3461
+ // the instance.
3462
+ const instance = searchTokensOnInjector(injectorIndex, lView, token, previousTView, flags, hostTElementNode);
3463
+ if (instance !== NOT_FOUND) {
3464
+ return instance;
3467
3465
  }
3468
3466
  }
3467
+ parentLocation = lView[injectorIndex + 8 /* PARENT */];
3468
+ if (parentLocation !== NO_PARENT_INJECTOR &&
3469
+ shouldSearchParent(flags, lView[TVIEW].data[injectorIndex + 8 /* TNODE */] === hostTElementNode) &&
3470
+ bloomHasToken(bloomHash, injectorIndex, lView)) {
3471
+ // The def wasn't found anywhere on this node, so it was a false positive.
3472
+ // Traverse up the tree and continue searching.
3473
+ previousTView = tView;
3474
+ injectorIndex = getParentInjectorIndex(parentLocation);
3475
+ lView = getParentInjectorView(parentLocation, lView);
3476
+ }
3477
+ else {
3478
+ // If we should not search parent OR If the ancestor bloom filter value does not have the
3479
+ // bit corresponding to the directive we can give up on traversing up to find the specific
3480
+ // injector.
3481
+ injectorIndex = -1;
3482
+ }
3469
3483
  }
3470
3484
  }
3471
- return lookupTokenUsingModuleInjector(lView, token, flags, notFoundValue);
3472
- }
3473
- const NOT_FOUND = {};
3474
- function createNodeInjector() {
3475
- return new NodeInjector(getCurrentTNode(), getLView());
3485
+ return notFoundValue;
3476
3486
  }
3477
3487
  function searchTokensOnInjector(injectorIndex, lView, token, previousTView, flags, hostTElementNode) {
3478
3488
  const currentTView = lView[TVIEW];
@@ -3646,6 +3656,10 @@ class NodeInjector {
3646
3656
  return getOrCreateInjectable(this._tNode, this._lView, token, flags, notFoundValue);
3647
3657
  }
3648
3658
  }
3659
+ /** Creates a `NodeInjector` for the current node. */
3660
+ function createNodeInjector() {
3661
+ return new NodeInjector(getCurrentTNode(), getLView());
3662
+ }
3649
3663
  /**
3650
3664
  * @codeGenApi
3651
3665
  */
@@ -3684,6 +3698,73 @@ function getFactoryOf(type) {
3684
3698
  }
3685
3699
  return getFactoryDef(type);
3686
3700
  }
3701
+ /**
3702
+ * Returns a value from the closest embedded or node injector.
3703
+ *
3704
+ * @param tNode The Node where the search for the injector should start
3705
+ * @param lView The `LView` that contains the `tNode`
3706
+ * @param token The token to look for
3707
+ * @param flags Injection flags
3708
+ * @param notFoundValue The value to return when the injection flags is `InjectFlags.Optional`
3709
+ * @returns the value from the injector, `null` when not found, or `notFoundValue` if provided
3710
+ */
3711
+ function lookupTokenUsingEmbeddedInjector(tNode, lView, token, flags, notFoundValue) {
3712
+ let currentTNode = tNode;
3713
+ let currentLView = lView;
3714
+ // When an LView with an embedded view injector is inserted, it'll likely be interlaced with
3715
+ // nodes who may have injectors (e.g. node injector -> embedded view injector -> node injector).
3716
+ // Since the bloom filters for the node injectors have already been constructed and we don't
3717
+ // have a way of extracting the records from an injector, the only way to maintain the correct
3718
+ // hierarchy when resolving the value is to walk it node-by-node while attempting to resolve
3719
+ // the token at each level.
3720
+ while (currentTNode !== null && currentLView !== null &&
3721
+ (currentLView[FLAGS] & 2048 /* HasEmbeddedViewInjector */) &&
3722
+ !(currentLView[FLAGS] & 512 /* IsRoot */)) {
3723
+ ngDevMode && assertTNodeForLView(currentTNode, currentLView);
3724
+ // Note that this lookup on the node injector is using the `Self` flag, because
3725
+ // we don't want the node injector to look at any parent injectors since we
3726
+ // may hit the embedded view injector first.
3727
+ const nodeInjectorValue = lookupTokenUsingNodeInjector(currentTNode, currentLView, token, flags | InjectFlags.Self, NOT_FOUND);
3728
+ if (nodeInjectorValue !== NOT_FOUND) {
3729
+ return nodeInjectorValue;
3730
+ }
3731
+ // Has an explicit type due to a TS bug: https://github.com/microsoft/TypeScript/issues/33191
3732
+ let parentTNode = currentTNode.parent;
3733
+ // `TNode.parent` includes the parent within the current view only. If it doesn't exist,
3734
+ // it means that we've hit the view boundary and we need to go up to the next view.
3735
+ if (!parentTNode) {
3736
+ // Before we go to the next LView, check if the token exists on the current embedded injector.
3737
+ const embeddedViewInjector = currentLView[EMBEDDED_VIEW_INJECTOR];
3738
+ if (embeddedViewInjector) {
3739
+ const embeddedViewInjectorValue = embeddedViewInjector.get(token, NOT_FOUND, flags);
3740
+ if (embeddedViewInjectorValue !== NOT_FOUND) {
3741
+ return embeddedViewInjectorValue;
3742
+ }
3743
+ }
3744
+ // Otherwise keep going up the tree.
3745
+ parentTNode = getTNodeFromLView(currentLView);
3746
+ currentLView = currentLView[DECLARATION_VIEW];
3747
+ }
3748
+ currentTNode = parentTNode;
3749
+ }
3750
+ return notFoundValue;
3751
+ }
3752
+ /** Gets the TNode associated with an LView inside of the declaration view. */
3753
+ function getTNodeFromLView(lView) {
3754
+ const tView = lView[TVIEW];
3755
+ const tViewType = tView.type;
3756
+ // The parent pointer differs based on `TView.type`.
3757
+ if (tViewType === 2 /* Embedded */) {
3758
+ ngDevMode && assertDefined(tView.declTNode, 'Embedded TNodes should have declaration parents.');
3759
+ return tView.declTNode;
3760
+ }
3761
+ else if (tViewType === 1 /* Component */) {
3762
+ // Components don't have `TView.declTNode` because each instance of component could be
3763
+ // inserted in different location, hence `TView.declTNode` is meaningless.
3764
+ return lView[T_HOST];
3765
+ }
3766
+ return null;
3767
+ }
3687
3768
 
3688
3769
  /**
3689
3770
  * @license
@@ -6167,11 +6248,14 @@ function getSanitizer() {
6167
6248
  const TRACKED_LVIEWS = new Map();
6168
6249
  // Used for generating unique IDs for LViews.
6169
6250
  let uniqueIdCounter = 0;
6170
- /** Starts tracking an LView and returns a unique ID that can be used for future lookups. */
6251
+ /** Gets a unique ID that can be assigned to an LView. */
6252
+ function getUniqueLViewId() {
6253
+ return uniqueIdCounter++;
6254
+ }
6255
+ /** Starts tracking an LView. */
6171
6256
  function registerLView(lView) {
6172
- const id = uniqueIdCounter++;
6173
- TRACKED_LVIEWS.set(id, lView);
6174
- return id;
6257
+ ngDevMode && assertNumber(lView[ID], 'LView must have an ID in order to be registered');
6258
+ TRACKED_LVIEWS.set(lView[ID], lView);
6175
6259
  }
6176
6260
  /** Gets an LView by its unique ID. */
6177
6261
  function getLViewById(id) {
@@ -6380,7 +6464,13 @@ function attachPatchData(target, data) {
6380
6464
  // Only attach the ID of the view in order to avoid memory leaks (see #41047). We only do this
6381
6465
  // for `LView`, because we have control over when an `LView` is created and destroyed, whereas
6382
6466
  // we can't know when to remove an `LContext`.
6383
- target[MONKEY_PATCH_KEY_NAME] = isLView(data) ? data[ID] : data;
6467
+ if (isLView(data)) {
6468
+ target[MONKEY_PATCH_KEY_NAME] = data[ID];
6469
+ registerLView(data);
6470
+ }
6471
+ else {
6472
+ target[MONKEY_PATCH_KEY_NAME] = data;
6473
+ }
6384
6474
  }
6385
6475
  /**
6386
6476
  * Returns the monkey-patch value data present on the target (which could be
@@ -9060,7 +9150,7 @@ class LViewDebug {
9060
9150
  attached: !!(flags & 128 /* Attached */),
9061
9151
  destroyed: !!(flags & 256 /* Destroyed */),
9062
9152
  isRoot: !!(flags & 512 /* IsRoot */),
9063
- indexWithinInitPhase: flags >> 11 /* IndexWithinInitPhaseShift */,
9153
+ indexWithinInitPhase: flags >> 12 /* IndexWithinInitPhaseShift */,
9064
9154
  };
9065
9155
  }
9066
9156
  get parent() {
@@ -9355,10 +9445,14 @@ function renderChildComponents(hostLView, components) {
9355
9445
  renderComponent$1(hostLView, components[i]);
9356
9446
  }
9357
9447
  }
9358
- function createLView(parentLView, tView, context, flags, host, tHostNode, rendererFactory, renderer, sanitizer, injector) {
9448
+ function createLView(parentLView, tView, context, flags, host, tHostNode, rendererFactory, renderer, sanitizer, injector, embeddedViewInjector) {
9359
9449
  const lView = ngDevMode ? cloneToLViewFromTViewBlueprint(tView) : tView.blueprint.slice();
9360
9450
  lView[HOST] = host;
9361
9451
  lView[FLAGS] = flags | 4 /* CreationMode */ | 128 /* Attached */ | 8 /* FirstLViewPass */;
9452
+ if (embeddedViewInjector !== null ||
9453
+ (parentLView && (parentLView[FLAGS] & 2048 /* HasEmbeddedViewInjector */))) {
9454
+ lView[FLAGS] |= 2048 /* HasEmbeddedViewInjector */;
9455
+ }
9362
9456
  resetPreOrderHookFlags(lView);
9363
9457
  ngDevMode && tView.declTNode && parentLView && assertTNodeForLView(tView.declTNode, parentLView);
9364
9458
  lView[PARENT] = lView[DECLARATION_VIEW] = parentLView;
@@ -9370,7 +9464,8 @@ function createLView(parentLView, tView, context, flags, host, tHostNode, render
9370
9464
  lView[SANITIZER] = sanitizer || parentLView && parentLView[SANITIZER] || null;
9371
9465
  lView[INJECTOR$1] = injector || parentLView && parentLView[INJECTOR$1] || null;
9372
9466
  lView[T_HOST] = tHostNode;
9373
- lView[ID] = registerLView(lView);
9467
+ lView[ID] = getUniqueLViewId();
9468
+ lView[EMBEDDED_VIEW_INJECTOR] = embeddedViewInjector;
9374
9469
  ngDevMode &&
9375
9470
  assertEqual(tView.type == 2 /* Embedded */ ? parentLView !== null : true, true, 'Embedded views must have parentLView');
9376
9471
  lView[DECLARATION_COMPONENT_VIEW] =
@@ -10379,7 +10474,6 @@ function instantiateAllDirectives(tView, lView, tNode, native) {
10379
10474
  function invokeDirectivesHostBindings(tView, lView, tNode) {
10380
10475
  const start = tNode.directiveStart;
10381
10476
  const end = tNode.directiveEnd;
10382
- const firstCreatePass = tView.firstCreatePass;
10383
10477
  const elementIndex = tNode.index;
10384
10478
  const currentDirectiveIndex = getCurrentDirectiveIndex();
10385
10479
  try {
@@ -10526,7 +10620,7 @@ function addComponentLogic(lView, hostTNode, def) {
10526
10620
  // Only component views should be added to the view tree directly. Embedded views are
10527
10621
  // accessed through their containers because they may be removed / re-added later.
10528
10622
  const rendererFactory = lView[RENDERER_FACTORY];
10529
- const componentView = addToViewTree(lView, createLView(lView, tView, null, def.onPush ? 64 /* Dirty */ : 16 /* CheckAlways */, native, hostTNode, rendererFactory, rendererFactory.createRenderer(native, def), null, null));
10623
+ const componentView = addToViewTree(lView, createLView(lView, tView, null, def.onPush ? 64 /* Dirty */ : 16 /* CheckAlways */, native, hostTNode, rendererFactory, rendererFactory.createRenderer(native, def), null, null, null));
10530
10624
  // Component view will always be created before any injected LContainers,
10531
10625
  // so this is a regular element, wrap it with the component view
10532
10626
  lView[hostTNode.index] = componentView;
@@ -12269,7 +12363,7 @@ function renderComponent(componentType /* Type as workaround for: Microsoft/Type
12269
12363
  const rootContext = createRootContext(opts.scheduler, opts.playerHandler);
12270
12364
  const renderer = rendererFactory.createRenderer(hostRNode, componentDef);
12271
12365
  const rootTView = createTView(0 /* Root */, null, null, 1, 0, null, null, null, null, null);
12272
- const rootView = createLView(null, rootTView, rootContext, rootFlags, null, null, rendererFactory, renderer, null, opts.injector || null);
12366
+ const rootView = createLView(null, rootTView, rootContext, rootFlags, null, null, rendererFactory, renderer, null, opts.injector || null, null);
12273
12367
  enterView(rootView);
12274
12368
  let component;
12275
12369
  try {
@@ -12324,7 +12418,7 @@ function createRootComponentView(rNode, def, rootView, rendererFactory, hostRend
12324
12418
  }
12325
12419
  }
12326
12420
  const viewRenderer = rendererFactory.createRenderer(rNode, def);
12327
- const componentView = createLView(rootView, getOrCreateTComponentView(def), null, def.onPush ? 64 /* Dirty */ : 16 /* CheckAlways */, rootView[index], tNode, rendererFactory, viewRenderer, sanitizer || null, null);
12421
+ const componentView = createLView(rootView, getOrCreateTComponentView(def), null, def.onPush ? 64 /* Dirty */ : 16 /* CheckAlways */, rootView[index], tNode, rendererFactory, viewRenderer, sanitizer || null, null, null);
12328
12422
  if (tView.firstCreatePass) {
12329
12423
  diPublicInInjector(getOrCreateNodeInjectorForNode(tNode, rootView), tView, def.type);
12330
12424
  markAsComponentHost(tView, tNode);
@@ -21172,7 +21266,7 @@ class Version {
21172
21266
  /**
21173
21267
  * @publicApi
21174
21268
  */
21175
- const VERSION = new Version('14.0.0-next.4');
21269
+ const VERSION = new Version('14.0.0-next.5');
21176
21270
 
21177
21271
  /**
21178
21272
  * @license
@@ -21577,22 +21671,28 @@ function getNamespace(elementName) {
21577
21671
  const name = elementName.toLowerCase();
21578
21672
  return name === 'svg' ? SVG_NAMESPACE : (name === 'math' ? MATH_ML_NAMESPACE : null);
21579
21673
  }
21580
- function createChainedInjector(rootViewInjector, moduleInjector) {
21581
- return {
21582
- get: (token, notFoundValue, flags) => {
21583
- const value = rootViewInjector.get(token, NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR, flags);
21584
- if (value !== NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR ||
21585
- notFoundValue === NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR) {
21586
- // Return the value from the root element injector when
21587
- // - it provides it
21588
- // (value !== NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR)
21589
- // - the module injector should not be checked
21590
- // (notFoundValue === NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR)
21591
- return value;
21592
- }
21593
- return moduleInjector.get(token, notFoundValue, flags);
21674
+ /**
21675
+ * Injector that looks up a value using a specific injector, before falling back to the module
21676
+ * injector. Used primarily when creating components or embedded views dynamically.
21677
+ */
21678
+ class ChainedInjector {
21679
+ constructor(injector, parentInjector) {
21680
+ this.injector = injector;
21681
+ this.parentInjector = parentInjector;
21682
+ }
21683
+ get(token, notFoundValue, flags) {
21684
+ const value = this.injector.get(token, NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR, flags);
21685
+ if (value !== NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR ||
21686
+ notFoundValue === NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR) {
21687
+ // Return the value from the root element injector when
21688
+ // - it provides it
21689
+ // (value !== NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR)
21690
+ // - the module injector should not be checked
21691
+ // (notFoundValue === NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR)
21692
+ return value;
21594
21693
  }
21595
- };
21694
+ return this.parentInjector.get(token, notFoundValue, flags);
21695
+ }
21596
21696
  }
21597
21697
  /**
21598
21698
  * Render3 implementation of {@link viewEngine_ComponentFactory}.
@@ -21620,7 +21720,7 @@ class ComponentFactory extends ComponentFactory$1 {
21620
21720
  }
21621
21721
  create(injector, projectableNodes, rootSelectorOrNode, ngModule) {
21622
21722
  ngModule = ngModule || this.ngModule;
21623
- const rootViewInjector = ngModule ? createChainedInjector(injector, ngModule.injector) : injector;
21723
+ const rootViewInjector = ngModule ? new ChainedInjector(injector, ngModule.injector) : injector;
21624
21724
  const rendererFactory = rootViewInjector.get(RendererFactory2, domRendererFactory3);
21625
21725
  const sanitizer = rootViewInjector.get(Sanitizer, null);
21626
21726
  const hostRenderer = rendererFactory.createRenderer(null, this.componentDef);
@@ -21635,7 +21735,7 @@ class ComponentFactory extends ComponentFactory$1 {
21635
21735
  const rootContext = createRootContext();
21636
21736
  // Create the root view. Uses empty TView and ContentTemplate.
21637
21737
  const rootTView = createTView(0 /* Root */, null, null, 1, 0, null, null, null, null, null);
21638
- const rootLView = createLView(null, rootTView, rootContext, rootFlags, null, null, rendererFactory, hostRenderer, sanitizer, rootViewInjector);
21738
+ const rootLView = createLView(null, rootTView, rootContext, rootFlags, null, null, rendererFactory, hostRenderer, sanitizer, rootViewInjector, null);
21639
21739
  // rootView is the parent when bootstrapping
21640
21740
  // TODO(misko): it looks like we are entering view here but we don't really need to as
21641
21741
  // `renderView` does that. However as the code is written it is needed because
@@ -22756,9 +22856,9 @@ const R3TemplateRef = class TemplateRef extends ViewEngineTemplateRef {
22756
22856
  this._declarationTContainer = _declarationTContainer;
22757
22857
  this.elementRef = elementRef;
22758
22858
  }
22759
- createEmbeddedView(context) {
22859
+ createEmbeddedView(context, injector) {
22760
22860
  const embeddedTView = this._declarationTContainer.tViews;
22761
- const embeddedLView = createLView(this._declarationLView, embeddedTView, context, 16 /* CheckAlways */, null, embeddedTView.declTNode, null, null, null, null);
22861
+ const embeddedLView = createLView(this._declarationLView, embeddedTView, context, 16 /* CheckAlways */, null, embeddedTView.declTNode, null, null, null, null, injector || null);
22762
22862
  const declarationLContainer = this._declarationLView[this._declarationTContainer.index];
22763
22863
  ngDevMode && assertLContainer(declarationLContainer);
22764
22864
  embeddedLView[DECLARATION_LCONTAINER] = declarationLContainer;
@@ -22874,8 +22974,17 @@ const R3ViewContainerRef = class ViewContainerRef extends VE_ViewContainerRef {
22874
22974
  get length() {
22875
22975
  return this._lContainer.length - CONTAINER_HEADER_OFFSET;
22876
22976
  }
22877
- createEmbeddedView(templateRef, context, index) {
22878
- const viewRef = templateRef.createEmbeddedView(context || {});
22977
+ createEmbeddedView(templateRef, context, indexOrOptions) {
22978
+ let index;
22979
+ let injector;
22980
+ if (typeof indexOrOptions === 'number') {
22981
+ index = indexOrOptions;
22982
+ }
22983
+ else if (indexOrOptions != null) {
22984
+ index = indexOrOptions.index;
22985
+ injector = indexOrOptions.injector;
22986
+ }
22987
+ const viewRef = templateRef.createEmbeddedView(context || {}, injector);
22879
22988
  this.insert(viewRef, index);
22880
22989
  return viewRef;
22881
22990
  }