Skip to content

Use module name as component selector prefix #5795

@jmendiara

Description

@jmendiara

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x] feature request

Versions.

$ ng --version
@angular/cli: 1.0.0
node: 6.10.0
os: darwin x64
@angular/animations: 4.0.1
@angular/common: 4.0.1
@angular/compiler: 4.0.1
@angular/core: 4.0.1
@angular/forms: 4.0.1
@angular/http: 4.0.1
@angular/material: 2.0.0-beta.2
@angular/platform-browser: 4.0.1
@angular/platform-browser-dynamic: 4.0.1
@angular/router: 4.0.1
@angular/cli: 1.0.0
@angular/compiler-cli: 4.0.1

Repro steps.

$ ng g m babies --routing
$ ng g c babies/detail 

this generates

@Component({
  selector: 'app-detail',
  templateUrl: './detail.component.html',
  styleUrls: ['./detail.component.scss']
})
//...

The log given by the failure.

Desired functionality.

As per https://angular.io/docs/ts/latest/guide/style-guide.html#!#02-07

Do use a custom prefix for a component selector. For example, the prefix toh represents from Tour of Heroes and the prefix admin represents an admin feature area.
Do use a prefix that identifies the feature area or the app itself.

When you create a component in a feature, it's likely that feature can be exported. Having app prefix when creating a component inside a feature asumes the feature should live inside an app context, and can cause more collisions.

Therefore, setting the module prefix to their components by default will lead to better practices

The expected result would be

$ ng g m babies --routing
$ ng g c babies/detail 

could generate

@Component({
  selector: 'babies-detail',
  templateUrl: './detail.component.html',
  styleUrls: ['./detail.component.scss']
})
//...

Mention any other details that might be useful.

Related #5794

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions