I need to create a component without the folder. I am using Angular-Cli command ng g c testing
to create the component. But, the command creates an folder wrapper for the newly created component.

- 6,971
- 4
- 41
- 57

- 411
- 1
- 6
- 11
-
You don't need to use `ng` command line to create a component, just manually create one? – penleychan May 28 '19 at 05:01
-
No sir, manually create is easy, but import app.module.ts also manual import that component. So, thats the reason to using commands – saravanam cs May 28 '19 at 09:10
-
And it's hard to do that manually...? Regardless someone already provided you a way. – penleychan May 28 '19 at 11:09
-
1@penleychan I know this is a somewhat zombie thread, but in case people get confused... Doing that manually actually exposes you to typos plus is more time consuming. This is exactly why CLI was created. I've seen someone rightclicking folder and creating each file separatelly. Then spelling error happend and the whole team had a fun time figuring this out. – Tyiliyra Mar 30 '20 at 07:54
5 Answers
You can use --flat
flag.
ng g c test --flat
For more information follow this link
flat = true | false
When true creates the new files at the top level of the current project.
Default: false

- 10,349
- 9
- 44
- 84

- 1,142
- 3
- 13
- 21
ng generate module app-routing --flat --module=app
or
ng g m app-routing --flat --module=app
--flat
creates the file in src/app instead of creating a folder. If you want to skip creating folder, you can use --flat
flag
--module=app
tells the CLI to register it in the imports array of the AppModule.
ng g c test --flat
ng g c test --skipTests=true
--skipTests=true
is not to create any test files.
hope you understood. Happy coding :)

- 2,676
- 1
- 30
- 35
Cd into the folder in which you want to create the component then run the following command:
ng g c testing --flat
The --flat
option, will create and place the component in your current working directory.

- 7,780
- 3
- 46
- 42
ng g c test1 --flat --inline-template --inline-style
- --flat allows us to create the new component without new folder.
- --inline allows us to keep the template/style in the component file itself instead of creating separate file for those.

- 343
- 1
- 8
-
you are welcome! Please mark any one of the answer as correct one. So that others can use it. – Veeraragavan May 28 '19 at 09:07
-
You can create components anywhere inside the app folder without using commands if you are using any IDE for development like Visual Studio Code or Atom. Use the new file icon or New File option from File Menu,
but I would suggest you use a folder structure for better maintenance

- 301
- 5
- 18