Skip to content

Commit 316c91b

Browse files
devversionatscott
authored andcommitted
fix(core): deprecate moduleId @Component property (#49496)
The `moduleId` directive field does not have any effect as of Ivy. In View Engine it was used for resolving template and styles relative to the component source location- but ultimately this is not needed as the Angular compiler knows the source file location at build time, and at runtime never even consulted `moduleId`. An XHR is always issue using the extact specified URL. For Angular CLI users, relative URLs in JIT are still possible because the CLI has a TS transform that will replace the references with actual Webpack imports. `moduleId` does not seem worth keeping in the future, as it's not used currently, and even if we would consider supporting relative JIT resource URLs through it, it would be deeply coupled to CommonJS `module.id`. DEPRECATED: The `@Directive`/`@Component` `moduleId` property is now deprecated. It did not have any effect for multiple major versions and will be removed in v17. PR Close #49496
1 parent 22a6412 commit 316c91b

File tree

4 files changed

+5
-1
lines changed

4 files changed

+5
-1
lines changed

aio/content/guide/cheatsheet.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464

6565
| Component configuration <br /> `@Component` extends `@Directive`, so the `@Directive` configuration applies to components as well | Details |
6666
|:--- |:--- |
67-
| <code-example format="typescript" hideCopy language="typescript"> moduleId: module.id </code-example> | If set, the `templateUrl` and `styleUrl` are resolved relative to the component. |
6867
| <code-example format="typescript" hideCopy language="typescript"> viewProviders: [MyService, { provide: &hellip; }] </code-example> | List of dependency injection providers scoped to this component's view. |
6968
| <code-example format="typescript" hideCopy language="typescript"> template: 'Hello {{name}}' &NewLine;templateUrl: 'my-component.html' </code-example> | Inline template or external template URL of the component's view. |
7069
| <code-example format="typescript" hideCopy language="typescript"> styles: ['.primary {color: red}'] &NewLine;styleUrls: ['my-component.css'] </code-example> | List of inline CSS styles or external stylesheet URLs for styling the component's view. |

aio/content/guide/deprecations.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ v16 - v19
109109
| `@angular/common` | [`NgComponentOutlet.ngComponentOutletNgModuleFactory`](#common) | v14 | v17 |
110110
| `@angular/common` | [`DatePipe` - `DATE_PIPE_DEFAULT_TIMEZONE`](api/common/DATE_PIPE_DEFAULT_TIMEZONE) | v15 | v17 |
111111
| `@angular/core` | NgModule and `'any'` options for [`providedIn`](#core) | v15 | v17 |
112+
| `@angular/core` | [`@Component.moduleId`](api/core/Component#moduleId) | v16 | v17 |
112113
| `@angular/router` | [`RouterLinkWithHref` directive](#router) | v15 | v17 |
113114
| `@angular/router` | [Router writeable properties](#router-writable-properties) | v15.1 | v17 |
114115
| `@angular/router` | [Router CanLoad guards](#router-can-load) | v15.1 | v17 |
@@ -176,6 +177,8 @@ In the [API reference section](api) of this site, deprecated APIs are indicated
176177
| [`providedIn`](api/core/Injectable#providedIn) with NgModule | Prefer `'root'` providers, or use NgModule `providers` if scoping to an NgModule is necessary | v15 | none |
177178
| [`providedIn: 'any'`](api/core/Injectable#providedIn) | none | v15 | This option has confusing semantics and nearly zero usage. |
178179
| [`EnvironmentInjector.runInContext`](api/core/EnvironmentInjector#runInContext) | `runInInjectionContext` | v16 | `runInInjectionContext` is a more flexible operation which supports element injectors as well |
180+
| [`@Component.moduleId`](api/core/Component#moduleId) | none | v16 |
181+
179182

180183
<a id="testing"></a>
181184

goldens/public-api/core/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ export interface Component extends Directive {
189189
encapsulation?: ViewEncapsulation;
190190
imports?: (Type<any> | ReadonlyArray<any>)[];
191191
interpolation?: [string, string];
192+
// @deprecated
192193
moduleId?: string;
193194
preserveWhitespaces?: boolean;
194195
schemas?: SchemaMetadata[];

packages/core/src/metadata/directives.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ export interface Component extends Directive {
543543
* SystemJS exposes the `__moduleName` variable within each module.
544544
* In CommonJS, this can be set to `module.id`.
545545
*
546+
* @deprecated This option does not have any effect. Will be removed in Angular v17.
546547
*/
547548
moduleId?: string;
548549

0 commit comments

Comments
 (0)