Skip to content

Commit da090f9

Browse files
committed
fix(@schematics/angular): use service decorator in ng generate
Updates the `service` schematic in `ng generate` to use the `@Service` decorator instead of `@Injectable`.
1 parent b5ba365 commit da090f9

3 files changed

Lines changed: 16 additions & 16 deletions

File tree

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { Injectable } from '@angular/core';
1+
import { Service } from '@angular/core';
22

3-
@Injectable({
4-
providedIn: 'root',
5-
})
3+
@Service()
64
export class <%= classifiedName %> {
75

86
}

packages/schematics/angular/service/index_spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ describe('Service Schematic', () => {
3636
skipPackageJson: false,
3737
};
3838
let appTree: UnitTestTree;
39+
3940
beforeEach(async () => {
4041
appTree = await schematicRunner.runSchematic('workspace', workspaceOptions);
4142
appTree = await schematicRunner.runSchematic('application', appOptions, appTree);
@@ -50,12 +51,13 @@ describe('Service Schematic', () => {
5051
expect(files).toContain('/projects/bar/src/app/foo/foo.ts');
5152
});
5253

53-
it('service should be tree-shakeable', async () => {
54+
it('should use @Service decorator', async () => {
5455
const options = { ...defaultOptions };
5556

5657
const tree = await schematicRunner.runSchematic('service', options, appTree);
5758
const content = tree.readContent('/projects/bar/src/app/foo/foo.ts');
58-
expect(content).toMatch(/providedIn: 'root',/);
59+
expect(content).toMatch(/@Service\(\)/);
60+
expect(content).toMatch(/import \{ Service \} from '@angular\/core'/);
5961
});
6062

6163
it('should respect the skipTests flag', async () => {

packages/schematics/angular/service/schema.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema",
3-
"$id": "SchematicsAngularService",
4-
"title": "Angular Service Options Schema",
3+
"$id": "SchematicsAngularInjectable",
4+
"title": "Angular Injectable Options Schema",
55
"type": "object",
66
"additionalProperties": false,
7-
"description": "Creates a new service in your project. Services are used to encapsulate reusable logic, such as data access, API calls, or utility functions. This schematic simplifies the process of generating a new service with the necessary files and boilerplate code.",
7+
"description": "Creates a new injectable in your project. Injectables are used to encapsulate reusable logic, such as data access, API calls, or utility functions. This schematic simplifies the process of generating a new injectable with the necessary files and boilerplate code.",
88
"properties": {
99
"name": {
1010
"type": "string",
11-
"description": "The name for the new service. This will be used to create the service's class and spec files (e.g., `my-service.service.ts` and `my-service.service.spec.ts`).",
11+
"description": "The name for the new injectable. This will be used to create the injectable class and spec files (e.g., `my-inj.service.ts` and `my-inj.service.spec.ts`).",
1212
"$default": {
1313
"$source": "argv",
1414
"index": 0
1515
},
16-
"x-prompt": "What name would you like to use for the service?"
16+
"x-prompt": "What name would you like to use for the injectable?"
1717
},
1818
"path": {
1919
"type": "string",
2020
"$default": {
2121
"$source": "workingDirectory"
2222
},
23-
"description": "The path where the service files should be created, relative to the workspace root. If not provided, the service will be created in the project's `src/app` directory.",
23+
"description": "The path where the injectable files should be created, relative to the workspace root. If not provided, the injectable will be created in the project's `src/app` directory.",
2424
"visible": false
2525
},
2626
"project": {
2727
"type": "string",
28-
"description": "The name of the project where the service should be added. If not specified, the CLI will determine the project from the current directory.",
28+
"description": "The name of the project where the injectable should be added. If not specified, the CLI will determine the project from the current directory.",
2929
"$default": {
3030
"$source": "projectName"
3131
}
3232
},
3333
"flat": {
3434
"type": "boolean",
3535
"default": true,
36-
"description": "Creates files at the top level of the project or the given path. If set to false, a new folder with the service's name will be created to contain the files."
36+
"description": "Creates files at the top level of the project or the given path. If set to false, a new folder with the injectable's name will be created to contain the files."
3737
},
3838
"skipTests": {
3939
"type": "boolean",
40-
"description": "Skip the generation of a unit test file `spec.ts` for the service.",
40+
"description": "Skip the generation of a unit test file `spec.ts` for the injectable.",
4141
"default": false
4242
},
4343
"type": {
4444
"type": "string",
45-
"description": "Append a custom type to the service's filename. For example, if you set the type to `service`, the file will be named `my-service.service.ts`."
45+
"description": "Append a custom type to the injectable's filename. For example, if you set the type to `service`, the file will be named `my-inj.service.ts`."
4646
},
4747
"addTypeToClassName": {
4848
"type": "boolean",

0 commit comments

Comments
 (0)