-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
[typescript-angular] - Remove legacy constructor decorators in favor of native Angular inject() Fn #24891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
[typescript-angular] - Remove legacy constructor decorators in favor of native Angular inject() Fn #24891
Changes from all commits
57462f2
ea8fd53
284b528
27f15f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| {{>licenseInfo}} | ||
| /* tslint:disable:no-unused-variable member-ordering */ | ||
|
|
||
| import { Inject, Injectable, Optional } from '@angular/core'; | ||
| import { inject, Injectable } from '@angular/core'; | ||
| import { HttpClient, HttpHeaders, HttpParams, | ||
| HttpResponse, HttpEvent{{#httpContextInOptions}}, HttpContext {{/httpContextInOptions}} | ||
| } from '@angular/common/http'; | ||
|
|
@@ -62,8 +62,13 @@ export class {{classname}} extends BaseService implements {{classname}}Interface | |
| export class {{classname}} extends BaseService { | ||
| {{/withInterfaces}} | ||
|
|
||
| constructor(protected httpClient: HttpClient, @Optional() @Inject(BASE_PATH) basePath: string|string[], @Optional() configuration?: {{configurationClassName}}) { | ||
| super(basePath, configuration); | ||
| protected httpClient: HttpClient = inject(HttpClient); | ||
|
|
||
| constructor() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Consumers that instantiate a generated service directly now get Prompt for AI agents |
||
| super( | ||
| inject(BASE_PATH, { optional: true }) ?? undefined, | ||
| inject({{configurationClassName}}, { optional: true }) ?? undefined | ||
| ); | ||
| } | ||
|
|
||
| {{#operation}} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { NgModule, ModuleWithProviders, SkipSelf, Optional } from '@angular/core'; | ||
| import { NgModule, ModuleWithProviders, inject } from '@angular/core'; | ||
| import { Configuration } from './configuration'; | ||
| import { HttpClient } from '@angular/common/http'; | ||
|
|
||
|
|
@@ -17,12 +17,14 @@ export class ApiModule { | |
| }; | ||
| } | ||
|
|
||
| constructor( @Optional() @SkipSelf() parentModule: ApiModule, | ||
| @Optional() http: HttpClient) { | ||
| if (parentModule) { | ||
| private parentModule: ApiModule = inject(ApiModule, { optional: true, skipSelf: true }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: The template now emits Prompt for AI agents |
||
| private http: HttpClient = inject(HttpClient, { optional: true }); | ||
|
|
||
| constructor() { | ||
| if (this.parentModule) { | ||
| throw new Error('ApiModule is already loaded. Import in your base AppModule only.'); | ||
| } | ||
| if (!http) { | ||
| if (!this.http) { | ||
| throw new Error('You need to import the HttpClientModule in your AppModule! \n' + | ||
| 'See also https://github.com/angular/angular/issues/20575'); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: When
ngVersionis 9–13, this unconditionalinjectimport makes the generated client fail to compile even though those Angular versions remain supported. Gate the functional-injection template on the minimum Angular version that providesinject, or raise the generator’s supported minimum.Prompt for AI agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC this would break backwards compatibility, so i guess we should avoid that until we officially drop support for ng < 14