@angular/core 14.0.0-rc.1 → 14.0.0

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/fesm2020/core.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Angular v14.0.0-rc.1
2
+ * @license Angular v14.0.0
3
3
  * (c) 2010-2022 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
@@ -954,8 +954,8 @@ function ɵɵdefineComponent(componentDefinition) {
954
954
  */
955
955
  function ɵɵsetComponentScope(type, directives, pipes) {
956
956
  const def = type.ɵcmp;
957
- def.directiveDefs = () => directives.map(extractDirectiveDef);
958
- def.pipeDefs = () => pipes.map(getPipeDef$1);
957
+ def.directiveDefs = () => (typeof directives === 'function' ? directives() : directives).map(extractDirectiveDef);
958
+ def.pipeDefs = () => (typeof pipes === 'function' ? pipes() : pipes).map(getPipeDef$1);
959
959
  }
960
960
  function extractDirectiveDef(type) {
961
961
  return getComponentDef(type) || getDirectiveDef(type);
@@ -4858,9 +4858,9 @@ function setCurrentInjector(injector) {
4858
4858
  function injectInjectorOnly(token, flags = InjectFlags.Default) {
4859
4859
  if (_currentInjector === undefined) {
4860
4860
  const errorMessage = (typeof ngDevMode === 'undefined' || ngDevMode) ?
4861
- `inject() must be called from an injection context` :
4861
+ `inject() must be called from an injection context (a constructor, a factory function or a field initializer)` :
4862
4862
  '';
4863
- throw new RuntimeError(203 /* RuntimeErrorCode.MISSING_INJECTION_CONTEXT */, errorMessage);
4863
+ throw new RuntimeError(-203 /* RuntimeErrorCode.MISSING_INJECTION_CONTEXT */, errorMessage);
4864
4864
  }
4865
4865
  else if (_currentInjector === null) {
4866
4866
  return injectRootLimpMode(token, undefined, flags);
@@ -4895,29 +4895,71 @@ Please check that 1) the type for the parameter at index ${index} is correct and
4895
4895
  }
4896
4896
  /**
4897
4897
  * Injects a token from the currently active injector.
4898
- *
4899
- * Must be used in the context of a factory function such as one defined for an
4900
- * `InjectionToken`. Throws an error if not called from such a context.
4901
- *
4902
- * Within such a factory function, using this function to request injection of a dependency
4903
- * is faster and more type-safe than providing an additional array of dependencies
4904
- * (as has been common with `useFactory` providers).
4905
- *
4906
- * @param token The injection token for the dependency to be injected.
4898
+ * `inject` is only supported during instantiation of a dependency by the DI system. It can be used
4899
+ * during:
4900
+ * - Construction (via the `constructor`) of a class being instantiated by the DI system, such
4901
+ * as an `@Injectable` or `@Component`.
4902
+ * - In the initializer for fields of such classes.
4903
+ * - In the factory function specified for `useFactory` of a `Provider` or an `@Injectable`.
4904
+ * - In the `factory` function specified for an `InjectionToken`.
4905
+ *
4906
+ * @param token A token that represents a dependency that should be injected.
4907
4907
  * @param flags Optional flags that control how injection is executed.
4908
4908
  * The flags correspond to injection strategies that can be specified with
4909
4909
  * parameter decorators `@Host`, `@Self`, `@SkipSef`, and `@Optional`.
4910
- * @returns the injected value if injection is successful, `null` otherwise.
4910
+ * @returns the injected value if operation is successful, `null` otherwise.
4911
+ * @throws if called outside of a supported context.
4911
4912
  *
4912
4913
  * @usageNotes
4914
+ * In practice the `inject()` calls are allowed in a constructor, a constructor parameter and a
4915
+ * field initializer:
4913
4916
  *
4914
- * ### Example
4917
+ * ```typescript
4918
+ * @Injectable({providedIn: 'root'})
4919
+ * export class Car {
4920
+ * radio: Radio|undefined;
4921
+ * // OK: field initializer
4922
+ * spareTyre = inject(Tyre);
4915
4923
  *
4916
- * {@example core/di/ts/injector_spec.ts region='ShakableInjectionToken'}
4924
+ * constructor() {
4925
+ * // OK: constructor body
4926
+ * this.radio = inject(Radio);
4927
+ * }
4928
+ * }
4929
+ * ```
4930
+ *
4931
+ * It is also legal to call `inject` from a provider's factory:
4932
+ *
4933
+ * ```typescript
4934
+ * providers: [
4935
+ * {provide: Car, useFactory: () => {
4936
+ * // OK: a class factory
4937
+ * const engine = inject(Engine);
4938
+ * return new Car(engine);
4939
+ * }}
4940
+ * ]
4941
+ * ```
4942
+ *
4943
+ * Calls to the `inject()` function outside of the class creation context will result in error. Most
4944
+ * notably, calls to `inject()` are disallowed after a class instance was created, in methods
4945
+ * (including lifecycle hooks):
4946
+ *
4947
+ * ```typescript
4948
+ * @Component({ ... })
4949
+ * export class CarComponent {
4950
+ * ngOnInit() {
4951
+ * // ERROR: too late, the component instance was already created
4952
+ * const engine = inject(Engine);
4953
+ * engine.start();
4954
+ * }
4955
+ * }
4956
+ * ```
4917
4957
  *
4918
4958
  * @publicApi
4919
4959
  */
4920
- const inject = ɵɵinject;
4960
+ function inject(token, flags = InjectFlags.Default) {
4961
+ return ɵɵinject(token, flags);
4962
+ }
4921
4963
  function injectArgs(types) {
4922
4964
  const args = [];
4923
4965
  for (let i = 0; i < types.length; i++) {
@@ -8831,8 +8873,38 @@ const INJECTOR_DEF_TYPES = new InjectionToken('INJECTOR_DEF_TYPES');
8831
8873
  * another environment injector (such as a route injector). They should not be used in component
8832
8874
  * providers.
8833
8875
  *
8834
- * @returns The collected providers from the specified list of types.
8876
+ * More information about standalone components can be found in [this
8877
+ * guide](guide/standalone-components).
8878
+ *
8879
+ * @usageNotes
8880
+ * The results of the `importProvidersFrom` call can be used in the `bootstrapApplication` call:
8881
+ *
8882
+ * ```typescript
8883
+ * await bootstrapApplication(RootComponent, {
8884
+ * providers: [
8885
+ * importProvidersFrom(NgModuleOne, NgModuleTwo)
8886
+ * ]
8887
+ * });
8888
+ * ```
8889
+ *
8890
+ * You can also use the `importProvidersFrom` results in the `providers` field of a route, when a
8891
+ * standalone component is used:
8892
+ *
8893
+ * ```typescript
8894
+ * export const ROUTES: Route[] = [
8895
+ * {
8896
+ * path: 'foo',
8897
+ * providers: [
8898
+ * importProvidersFrom(NgModuleOne, NgModuleTwo)
8899
+ * ],
8900
+ * component: YourStandaloneComponent
8901
+ * }
8902
+ * ];
8903
+ * ```
8904
+ *
8905
+ * @returns Collected providers from the specified list of types.
8835
8906
  * @publicApi
8907
+ * @developerPreview
8836
8908
  */
8837
8909
  function importProvidersFrom(...sources) {
8838
8910
  return { ɵproviders: internalImportProvidersFrom(true, sources) };
@@ -9110,6 +9182,8 @@ function getNullInjector() {
9110
9182
  /**
9111
9183
  * An `Injector` that's part of the environment injector hierarchy, which exists outside of the
9112
9184
  * component tree.
9185
+ *
9186
+ * @developerPreview
9113
9187
  */
9114
9188
  class EnvironmentInjector {
9115
9189
  }
@@ -11368,6 +11442,55 @@ function createTNodeAtIndex(tView, index, type, name, attrs) {
11368
11442
  }
11369
11443
  return tNode;
11370
11444
  }
11445
+ /**
11446
+ * WARNING: this is a **dev-mode only** function (thus should always be guarded by the `ngDevMode`)
11447
+ * and must **not** be used in production bundles. The function makes megamorphic reads, which might
11448
+ * be too slow for production mode and also it relies on the constructor function being available.
11449
+ *
11450
+ * Gets a reference to the host component def (where a current component is declared).
11451
+ *
11452
+ * @param lView An `LView` that represents a current component that is being rendered.
11453
+ */
11454
+ function getDeclarationComponentDef(lView) {
11455
+ !ngDevMode && throwError('Must never be called in production mode');
11456
+ const declarationLView = lView[DECLARATION_COMPONENT_VIEW];
11457
+ const context = declarationLView[CONTEXT];
11458
+ // Unable to obtain a context.
11459
+ if (!context)
11460
+ return null;
11461
+ return context.constructor ? getComponentDef(context.constructor) : null;
11462
+ }
11463
+ /**
11464
+ * WARNING: this is a **dev-mode only** function (thus should always be guarded by the `ngDevMode`)
11465
+ * and must **not** be used in production bundles. The function makes megamorphic reads, which might
11466
+ * be too slow for production mode.
11467
+ *
11468
+ * Checks if the current component is declared inside of a standalone component template.
11469
+ *
11470
+ * @param lView An `LView` that represents a current component that is being rendered.
11471
+ */
11472
+ function isHostComponentStandalone(lView) {
11473
+ !ngDevMode && throwError('Must never be called in production mode');
11474
+ const componentDef = getDeclarationComponentDef(lView);
11475
+ // Treat host component as non-standalone if we can't obtain the def.
11476
+ return !!(componentDef?.standalone);
11477
+ }
11478
+ /**
11479
+ * WARNING: this is a **dev-mode only** function (thus should always be guarded by the `ngDevMode`)
11480
+ * and must **not** be used in production bundles. The function makes megamorphic reads, which might
11481
+ * be too slow for production mode.
11482
+ *
11483
+ * Constructs a string describing the location of the host component template. The function is used
11484
+ * in dev mode to produce error messages.
11485
+ *
11486
+ * @param lView An `LView` that represents a current component that is being rendered.
11487
+ */
11488
+ function getTemplateLocationDetails(lView) {
11489
+ !ngDevMode && throwError('Must never be called in production mode');
11490
+ const hostComponentDef = getDeclarationComponentDef(lView);
11491
+ const componentClassName = hostComponentDef?.type?.name;
11492
+ return componentClassName ? ` (used in the '${componentClassName}' component template)` : '';
11493
+ }
11371
11494
  /**
11372
11495
  * When elements are created dynamically after a view blueprint is created (e.g. through
11373
11496
  * i18nApply()), we need to adjust the blueprint for future
@@ -12036,7 +12159,7 @@ function elementPropertyInternal(tView, tNode, lView, propName, value, renderer,
12036
12159
  validateAgainstEventProperties(propName);
12037
12160
  if (!validateProperty(element, tNode.value, propName, tView.schemas)) {
12038
12161
  // Return here since we only log warnings for unknown properties.
12039
- handleUnknownPropertyError(propName, tNode.value);
12162
+ handleUnknownPropertyError(propName, tNode, lView);
12040
12163
  return;
12041
12164
  }
12042
12165
  ngDevMode.rendererSetProperty++;
@@ -12056,7 +12179,7 @@ function elementPropertyInternal(tView, tNode, lView, propName, value, renderer,
12056
12179
  // If the node is a container and the property didn't
12057
12180
  // match any of the inputs or schemas we should throw.
12058
12181
  if (ngDevMode && !matchingSchemas(tView.schemas, tNode.value)) {
12059
- handleUnknownPropertyError(propName, tNode.value);
12182
+ handleUnknownPropertyError(propName, tNode, lView);
12060
12183
  }
12061
12184
  }
12062
12185
  }
@@ -12157,13 +12280,60 @@ function matchingSchemas(schemas, tagName) {
12157
12280
  }
12158
12281
  return false;
12159
12282
  }
12283
+ /**
12284
+ * The set of known control flow directives.
12285
+ * We use this set to produce a more precises error message with a note
12286
+ * that the `CommonModule` should also be included.
12287
+ */
12288
+ const KNOWN_CONTROL_FLOW_DIRECTIVES = new Set(['ngIf', 'ngFor', 'ngSwitch', 'ngSwitchCase', 'ngSwitchDefault']);
12160
12289
  /**
12161
12290
  * Logs or throws an error that a property is not supported on an element.
12291
+ *
12162
12292
  * @param propName Name of the invalid property.
12163
- * @param tagName Name of the node on which we encountered the property.
12164
- */
12165
- function handleUnknownPropertyError(propName, tagName) {
12166
- const message = `Can't bind to '${propName}' since it isn't a known property of '${tagName}'.`;
12293
+ * @param tNode A `TNode` that represents a current component that is being rendered.
12294
+ * @param lView An `LView` that represents a current component that is being rendered.
12295
+ */
12296
+ function handleUnknownPropertyError(propName, tNode, lView) {
12297
+ let tagName = tNode.value;
12298
+ // Special-case a situation when a structural directive is applied to
12299
+ // an `<ng-template>` element, for example: `<ng-template *ngIf="true">`.
12300
+ // In this case the compiler generates the `ɵɵtemplate` instruction with
12301
+ // the `null` as the tagName. The directive matching logic at runtime relies
12302
+ // on this effect (see `isInlineTemplate`), thus using the 'ng-template' as
12303
+ // a default value of the `tNode.value` is not feasible at this moment.
12304
+ if (!tagName && tNode.type === 4 /* TNodeType.Container */) {
12305
+ tagName = 'ng-template';
12306
+ }
12307
+ const isHostStandalone = isHostComponentStandalone(lView);
12308
+ const templateLocation = getTemplateLocationDetails(lView);
12309
+ let message = `Can't bind to '${propName}' since it isn't a known property of '${tagName}'${templateLocation}.`;
12310
+ const schemas = `'${isHostStandalone ? '@Component' : '@NgModule'}.schemas'`;
12311
+ const importLocation = isHostStandalone ?
12312
+ 'included in the \'@Component.imports\' of this component' :
12313
+ 'a part of an @NgModule where this component is declared';
12314
+ if (KNOWN_CONTROL_FLOW_DIRECTIVES.has(propName)) {
12315
+ // Most likely this is a control flow directive (such as `*ngIf`) used in
12316
+ // a template, but the `CommonModule` is not imported.
12317
+ message += `\nIf the '${propName}' is an Angular control flow directive, ` +
12318
+ `please make sure that the 'CommonModule' is ${importLocation}.`;
12319
+ }
12320
+ else {
12321
+ // May be an Angular component, which is not imported/declared?
12322
+ message += `\n1. If '${tagName}' is an Angular component and it has the ` +
12323
+ `'${propName}' input, then verify that it is ${importLocation}.`;
12324
+ // May be a Web Component?
12325
+ if (tagName && tagName.indexOf('-') > -1) {
12326
+ message += `\n2. If '${tagName}' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' ` +
12327
+ `to the ${schemas} of this component to suppress this message.`;
12328
+ message += `\n3. To allow any property add 'NO_ERRORS_SCHEMA' to ` +
12329
+ `the ${schemas} of this component.`;
12330
+ }
12331
+ else {
12332
+ // If it's expected, the error can be suppressed by the `NO_ERRORS_SCHEMA` schema.
12333
+ message += `\n2. To allow any property add 'NO_ERRORS_SCHEMA' to ` +
12334
+ `the ${schemas} of this component.`;
12335
+ }
12336
+ }
12167
12337
  if (shouldThrowErrorOnUnknownProperty) {
12168
12338
  throw new RuntimeError(303 /* RuntimeErrorCode.UNKNOWN_BINDING */, message);
12169
12339
  }
@@ -14948,7 +15118,9 @@ function elementStartFirstCreatePass(index, tView, lView, native, name, attrsInd
14948
15118
  const attrs = getConstant(tViewConsts, attrsIndex);
14949
15119
  const tNode = getOrCreateTNode(tView, index, 2 /* TNodeType.Element */, name, attrs);
14950
15120
  const hasDirectives = resolveDirectives(tView, lView, tNode, getConstant(tViewConsts, localRefsIndex));
14951
- ngDevMode && validateElementIsKnown(native, tNode.value, tView.schemas, hasDirectives);
15121
+ if (ngDevMode) {
15122
+ validateElementIsKnown(native, lView, tNode.value, tView.schemas, hasDirectives);
15123
+ }
14952
15124
  if (tNode.attrs !== null) {
14953
15125
  computeStaticStyling(tNode, tNode.attrs, false);
14954
15126
  }
@@ -15085,11 +15257,12 @@ function ɵɵelement(index, name, attrsIndex, localRefsIndex) {
15085
15257
  * - the element is allowed by one of the schemas
15086
15258
  *
15087
15259
  * @param element Element to validate
15260
+ * @param lView An `LView` that represents a current component that is being rendered.
15088
15261
  * @param tagName Name of the tag to check
15089
15262
  * @param schemas Array of schemas
15090
15263
  * @param hasDirectives Boolean indicating that the element matches any directive
15091
15264
  */
15092
- function validateElementIsKnown(element, tagName, schemas, hasDirectives) {
15265
+ function validateElementIsKnown(element, lView, tagName, schemas, hasDirectives) {
15093
15266
  // If `schemas` is set to `null`, that's an indication that this Component was compiled in AOT
15094
15267
  // mode where this check happens at compile time. In JIT mode, `schemas` is always present and
15095
15268
  // defined as an array (as an empty array in case `schemas` field is not defined) and we should
@@ -15109,14 +15282,19 @@ function validateElementIsKnown(element, tagName, schemas, hasDirectives) {
15109
15282
  (typeof customElements !== 'undefined' && tagName.indexOf('-') > -1 &&
15110
15283
  !customElements.get(tagName));
15111
15284
  if (isUnknown && !matchingSchemas(schemas, tagName)) {
15112
- let message = `'${tagName}' is not a known element:\n`;
15113
- message += `1. If '${tagName}' is an Angular component, then verify that it is part of this module.\n`;
15285
+ const isHostStandalone = isHostComponentStandalone(lView);
15286
+ const templateLocation = getTemplateLocationDetails(lView);
15287
+ const schemas = `'${isHostStandalone ? '@Component' : '@NgModule'}.schemas'`;
15288
+ let message = `'${tagName}' is not a known element${templateLocation}:\n`;
15289
+ message += `1. If '${tagName}' is an Angular component, then verify that it is ${isHostStandalone ? 'included in the \'@Component.imports\' of this component' :
15290
+ 'a part of an @NgModule where this component is declared'}.\n`;
15114
15291
  if (tagName && tagName.indexOf('-') > -1) {
15115
- message += `2. If '${tagName}' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.`;
15292
+ message +=
15293
+ `2. If '${tagName}' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the ${schemas} of this component to suppress this message.`;
15116
15294
  }
15117
15295
  else {
15118
15296
  message +=
15119
- `2. To allow any element add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.`;
15297
+ `2. To allow any element add 'NO_ERRORS_SCHEMA' to the ${schemas} of this component.`;
15120
15298
  }
15121
15299
  if (shouldThrowErrorOnUnknownElement) {
15122
15300
  throw new RuntimeError(304 /* RuntimeErrorCode.UNKNOWN_ELEMENT */, message);
@@ -21609,7 +21787,7 @@ class Version {
21609
21787
  /**
21610
21788
  * @publicApi
21611
21789
  */
21612
- const VERSION = new Version('14.0.0-rc.1');
21790
+ const VERSION = new Version('14.0.0');
21613
21791
 
21614
21792
  /**
21615
21793
  * @license
@@ -22281,6 +22459,7 @@ class EnvironmentNgModuleRefAdapter extends NgModuleRef$1 {
22281
22459
  * Create a new environment injector.
22282
22460
  *
22283
22461
  * @publicApi
22462
+ * @developerPreview
22284
22463
  */
22285
22464
  function createEnvironmentInjector(providers, parent = null, debugName = null) {
22286
22465
  const adapter = new EnvironmentNgModuleRefAdapter(providers, parent, debugName);
@@ -22337,7 +22516,7 @@ StandaloneService.ɵprov = ɵɵdefineInjectable({
22337
22516
  factory: () => new StandaloneService(ɵɵinject(EnvironmentInjector)),
22338
22517
  });
22339
22518
  /**
22340
- * A feature that acts as a setup code for the {@see StandaloneService}.
22519
+ * A feature that acts as a setup code for the {@link StandaloneService}.
22341
22520
  *
22342
22521
  * The most important responsaibility of this feature is to expose the "getStandaloneInjector"
22343
22522
  * function (an entry points to a standalone injector creation) on a component definition object. We
@@ -24409,6 +24588,12 @@ function isStandalone(type) {
24409
24588
  const def = getComponentDef(type) || getDirectiveDef(type) || getPipeDef$1(type);
24410
24589
  return def !== null ? def.standalone : false;
24411
24590
  }
24591
+ function generateStandaloneInDeclarationsError(type, location) {
24592
+ const prefix = `Unexpected "${stringifyForError(type)}" found in the "declarations" array of the`;
24593
+ const suffix = `"${stringifyForError(type)}" is marked as standalone and can't be declared ` +
24594
+ 'in any NgModule - did you intend to import it instead (by adding it to the "imports" array)?';
24595
+ return `${prefix} ${location}, ${suffix}`;
24596
+ }
24412
24597
  function verifySemanticsOfNgModuleDef(moduleType, allowDuplicateDeclarationsInRoot, importingModule) {
24413
24598
  if (verifiedNgModule.get(moduleType))
24414
24599
  return;
@@ -24480,7 +24665,8 @@ function verifySemanticsOfNgModuleDef(moduleType, allowDuplicateDeclarationsInRo
24480
24665
  type = resolveForwardRef(type);
24481
24666
  const def = getComponentDef(type) || getDirectiveDef(type) || getPipeDef$1(type);
24482
24667
  if (def?.standalone) {
24483
- errors.push(`Unexpected "${stringifyForError(type)}" declaration in "${stringifyForError(moduleType)}" NgModule. "${stringifyForError(type)}" is marked as standalone and can't be declared in any NgModule - did you intend to import it?`);
24668
+ const location = `"${stringifyForError(moduleType)}" NgModule`;
24669
+ errors.push(generateStandaloneInDeclarationsError(type, location));
24484
24670
  }
24485
24671
  }
24486
24672
  function verifyExportsAreDeclaredOrReExported(type) {