In angular 2 I use
ng g c componentname
But It is not supported in Angular 4, so I created it manually, but it shows error that it is not a module.
There are mainly two ways to generate new component in Angular, using ng g c <component_name> , another way is that using ng generate component <component_name> . using one of these commands new component can be generated. Show activity on this post. ng generate component componentName.
CLI Component Generation It looks like the CLI automatically created the new folder to hold our new component in app/virtual-machines . In addition we see four new files associated with the automatically generated component.
The Angular CLI is a command-line interface tool that you use to initialize, develop, scaffold, and maintain Angular applications directly from a command shell.
ng g module NewModule to generate a module. ng g component new-module/new-component to create NewComponent.
In Angular4 this will work the same. If you get an error I think your problem is somewhere else.
In command prompt type
ng generate component YOURCOMPONENTNAME
There are even shorthands for this: the commands generate
can be used as g
and component
as c
:
ng g c YOURCOMPONENTNAME
you can use ng --help
, ng g --help
or ng g c --help
for the docs.
Ofcourse rename YOURCOMPONENTNAME to the name you would like to use.
Docs: angular-cli will add reference to components, directives and pipes automatically in the app.module.ts.
Update: This still functions in Angular version 8.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With