Skip to content

fix(@schematics/angular): use service decorator in ng generate#33105

Open
crisbeto wants to merge 1 commit intoangular:mainfrom
crisbeto:service-schematic
Open

fix(@schematics/angular): use service decorator in ng generate#33105
crisbeto wants to merge 1 commit intoangular:mainfrom
crisbeto:service-schematic

Conversation

@crisbeto
Copy link
Copy Markdown
Member

@crisbeto crisbeto commented Apr 30, 2026

Updates the service schematic in ng generate to use the @Service decorator instead of @Injectable. There's also a new --injectable flag to get back the old behavior.

Comment thread packages/schematics/angular/injectable/schema.json Outdated
Comment thread packages/schematics/angular/service/schema.json Outdated
@alan-agius4
Copy link
Copy Markdown
Collaborator

alan-agius4 commented Apr 30, 2026

Were there any discussions regarding the creation of a new schematic versus simply adding an option to the existing service schematic to support both @Injectable and @Service?

@crisbeto crisbeto force-pushed the service-schematic branch from 3136903 to c2e241e Compare April 30, 2026 09:00
@crisbeto crisbeto marked this pull request as ready for review April 30, 2026 09:05
@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: major This PR is targeted for the next major release labels Apr 30, 2026
@crisbeto
Copy link
Copy Markdown
Member Author

I mentioned in the design doc for @Service that I'm planning to change ng generate. I added the injectable schematic for symmetry, but I don't feel strongly about it.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new injectable schematic for generating Angular injectable classes and updates the existing service schematic to use a @Service decorator. The review feedback highlights several areas for improvement, including correcting a regex in the test suite that would cause failures, renaming variables and types to maintain consistency with the new schematic's purpose, removing an unused parameter, and updating documentation in the schema to accurately reflect default file naming.

Comment thread packages/schematics/angular/injectable/index_spec.ts Outdated
Comment thread packages/schematics/angular/injectable/index.ts Outdated
Comment thread packages/schematics/angular/injectable/index.ts Outdated
Comment thread packages/schematics/angular/injectable/index.ts Outdated
Comment thread packages/schematics/angular/injectable/index.ts Outdated
Comment thread packages/schematics/angular/injectable/index_spec.ts Outdated
Comment thread packages/schematics/angular/injectable/index_spec.ts Outdated
Comment thread packages/schematics/angular/injectable/schema.json Outdated
@crisbeto crisbeto force-pushed the service-schematic branch from c2e241e to c324ad8 Compare April 30, 2026 09:19
Copy link
Copy Markdown
Collaborator

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new schematic also needs to be added in

"@schematics/angular:service": {

@crisbeto crisbeto force-pushed the service-schematic branch from c324ad8 to 551da86 Compare April 30, 2026 09:27
@crisbeto
Copy link
Copy Markdown
Member Author

Updated the config file.

@alan-agius4
Copy link
Copy Markdown
Collaborator

@crisbeto, I synced with @clydin on this. We’d prefer to update the existing service schematic with an --injectable flag rather than introducing a separate schematic. We're looking to consolidate our schematics where possible.

@alan-agius4 alan-agius4 added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Apr 30, 2026
@crisbeto crisbeto force-pushed the service-schematic branch from 551da86 to 33ed558 Compare May 1, 2026 08:28
@crisbeto crisbeto changed the title Update schematics for @Service fix(@schematics/angular): use service decorator in ng generate May 1, 2026
@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels May 1, 2026
@crisbeto
Copy link
Copy Markdown
Member Author

crisbeto commented May 1, 2026

I've updated it to remove the injectable schematic and add a --injectable flag instead.

Updates the `service` schematic in `ng generate` to use the `@Service` decorator instead of `@Injectable`. There's also a new `--injectable` flag to get back the old behavior.
@crisbeto crisbeto force-pushed the service-schematic branch from 33ed558 to dc52fe0 Compare May 1, 2026 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer area: @schematics/angular target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants