Skip to content

Add skipProvidedIn option to service schematic #31670

@MeAkib

Description

@MeAkib

Command

generate

Description

Currently, when generating a service using ng g s service-name, the CLI always generates the service with providedIn: 'root' in the Injectable decorator.

For applications that prefer to manually provide services in specific modules or components rather than using the tree-shakeable pattern, developers must manually remove this metadata every time a service is generated.

Describe the solution you'd like

Generate service without providedIn (new behavior)

ng g s my-service --skip-provided-in

Generate service with providedIn: 'root' (default, current behavior)

ng g s my-service

Expected Output with --skip-provided-in:

import { Injectable } from '@angular/core';  
  
@Injectable()  
export class MyService {}

Current Output (default behavior, unchanged):

import { Injectable } from '@angular/core';  
  
@Injectable({  
  providedIn: 'root'  
})  
export class MyService {  

}

Configuration Support

{  
  "schematics": {  
    "@schematics/angular:service": {  
      "skipProvidedIn": true  
    }  
  }  
} 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions