Angular CLI
What is Angular CLI ?
The Angular CLI is tool that angular developers use to make it easy to create an Angular application that works and follows best practices right out of the box.
don't worry i'll make a series about the angular CLI,
angular CLI helps to create every piece of angular application with one line like component, services, pipes, and so on.
Today's post is all about Creating Angular Components using Angular CLI.
as i mentioned in the first post you have to install Angular CLI on your computer to use it , if you don't have Angular CLI you can install
npm install -g @angular/cli
this line of command will install angular CLI globally on your machine.
now let's go and make a fun of Angular CLI
To create a new component go the folder of your angular application and type this command
ng generate component ComponentName
Walaaaah ! that is it you just generated new component
so let's explain what that line of code did
first of all it will generate 4 files
- the template (.html) file
- the style (.css) file
- the component (.ts) file
- the test file
Also did register our component in the angular Module so we can use it's selector across our application
easy isn't it !
so there are some flags you can add when generating new component using angular CLI , we'll learn the for the up comming series
so let's see these two flags
- --skip-tests
- -dry-run
these two commands tell angular CLI to do some thing extra
ng generate component componentName --skip-tests
it will skip the test file on the new component as we saw above the 4 files angular generats one of the was test file it will not generate a test file each time you use this flag
ng generate component componentName -dry-run
this flag it shows you what this command do in the disk it will not create anything on your folder it will just show you the before -dry-run command what that command will do,
it just reports you what will happen and it will not create a single file on your disk
general use case of this command is when you are not sure what this command will do just test it with -dry-run and it will report you what would happen if this command is executed
don't worry if you did not understand clearly will talk about this commands in a separate topics
i hope you found some thing useful here thanks for you reading
Top comments (0)