Create Component without folder

柔情痞子 提交于 2019-12-24 11:24:55

问题


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.


回答1:


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




回答2:


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




回答3:


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.



回答4:


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 :)



来源:https://stackoverflow.com/questions/56335224/create-component-without-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!