11

It seems that when I used angular cli to generate components, services etc.by this command and name of component

ng g component myApp

It generate component folder and other files such as

my-app.component.ts

instead myapp.component.ts

My question is: Is there any command to generate components, services, etc. with camelCase names.

I researched for it, but nothing worked.

3
  • 2
    As of this writing, this feature is not available, but an issue has been opened on the angular-cli GitHub repo and it should be implemented soon. See this link for more info: angular-cli camelCase naming convention Commented Jul 17, 2017 at 18:05
  • 2
    Please note that the CLI follows the Angular Style Guide: angular.io/guide/styleguide. Commented Apr 2, 2018 at 18:14
  • Angular is considered opinionated, so for things like that you're just stuck with it. It is a conscious choice on their part to enforce kebab-case for selectors and folder/file names for components. This is beneficial because it reduces cognitive load by making it easy to visually distinguish between them and component names which are PascalCase Commented Sep 26, 2024 at 17:29

1 Answer 1

10

Angular Style Guide explicitly says to use my-app.component.ts for file names.

  • dash-case (or "kebab-case"): descriptive part of file names, component selectors

Reference: https://angular.io/guide/glossary

Sign up to request clarification or add additional context in comments.

2 Comments

Sure, we know. But what is the motivation/reason for this strange convention? Why is BigNiceComponent in big-nice.component.* instead of the logical BigNiceComponent.*?
The motivation is to avoid upper case in a URL, it would be a problem if you had stackoverflow.com/BigNiceComponent.ts and stackoverflow.com/bignicecomponent.ts or stackoverflow.com/big-nice-component.ts

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.