Skip to content
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

Use module name as component selector prefix #5795

Closed
jmendiara opened this issue Apr 2, 2017 · 4 comments
Closed

Use module name as component selector prefix #5795

jmendiara opened this issue Apr 2, 2017 · 4 comments
Milestone

Comments

@jmendiara
Copy link

jmendiara commented Apr 2, 2017

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

@sumitarora sumitarora self-assigned this Apr 4, 2017
@filipesilva
Copy link
Contributor

This is part of a larger-ish discussion regarding supporting several prefixes, and how to auto-determine them. I don't think there's a good way of auto-detecting though. The best way to do this atm is to use the --prefix flag when making a component.

@filipesilva filipesilva assigned Brocco and unassigned sumitarora May 4, 2017
@filipesilva filipesilva added type: discussion feature Issue that requests a new feature labels May 4, 2017
@hansl hansl unassigned Brocco Feb 6, 2018
@SamanthaAdrichem
Copy link
Contributor

Atleast it should become 'app-babies-detail' if you ask me.

@ngbot ngbot bot added this to the Backlog milestone Oct 1, 2019
@kyliau kyliau added needs: discussion On the agenda for team meeting to determine next steps triage #1 labels May 26, 2020
@kyliau kyliau changed the title Creating a component in a feature/module should use the feature prefix Use module name as component selector prefix May 26, 2020
@kyliau
Copy link
Contributor

kyliau commented Jun 26, 2020

I think there are two components to this issue:

  1. Can user provide a custom prefix when running ng generate?
  2. Can CLI automatically determine the right prefix?

For (1), this is already possible with the --prefix flag.
In your example, you can run

$ ng g c babies/detail --prefix babies 

For (2) this is difficult to implement right for every user, with little benefit.

Since it's relatively low effort to achieve your intended behavior, and it's already possible to do that today, I'll close this issue for now. Please reopen if you'd like further discussion.

@kyliau kyliau closed this as completed Jun 26, 2020
@dgp1130 dgp1130 removed the needs: discussion On the agenda for team meeting to determine next steps label Jun 26, 2020
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jul 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants