The Angular 12 CLI is a tool that simplifies the lives of web developers. With the Angular CLI, you will be able to create, modify, and update projects very quickly and with ease. However, if you are unfamiliar with the CLI commands, you will be unable to rapidly create or edit your projects. In this chapter, we'll look at some of the most frequent CLI commands that you're likely to use when working on your project.
The common CLI commands
ng version command –you can only use this command if you have already installed angular on your computer. If you run this command, you will likely get the version of the Angular that you have installed.
npm install –g @angular/cli@^12.0.0 - this is the CLI command that you run when you would like to install angular 12 on your computer.
ng new <project-name> - after installing angular 12 in your computer, you should run this CLI command to create a new project, where at the <project-name>, you can input the name of your project.
For example, if you would like to create a new Angular 12 Application named CrudApp, you should run the following command.
Ng new CrudApp
ng generate- this command will allow you to change or modify files depending on your semantics. However, you can also type ng g, and the following will be displayed in your Angular CLI
ng g c - as we have learned, the ng g means to generate, now by placing c at the end, it means you have chosen to create a component. This command will build an angular component. For example
Ng g c carlo
ng g class <class name> – this CLI command is used to build a new class where the <class name> is used to specify the name of the class. For example, if you would like to create a new class, students, then you can learn the following command:
Ng g class<students>
ng g pipe <pipe-name> - This CLI command allows you to create a new pipe, wherein the <pipe name> you need to input the name of your pipe. For example, if you want to create the custom digit count, then run the following code:
ng g pipe digitcount
ng g directive – running this command will automatically generate a new angular directive in your project. For example, if you would like to create a new directive sample, run the following command:
ng g directive sample
ng test - if you want to check whether your application works as intended, you need to run this test command.
ng update - this command lets you update the dependencies of your current application
ng doc <keyword> - this command officially opens new angular documentation in your browser.
ng config - you run this command to retrieve or set the angular configurations values in the angular.json files for the workspace.
ng build – this command builds or compiles a new angular application
ng g service – this command is used to create services in angular
ng g web worker- this command is run when you want to generate a new web worker
ng g module – this command creates a new angular module
ng version – this command displays the version of the Angular that you have installed in your computer.
Conclusion
We have looked at some of the common CLI angular commands you are likely to use when building your angular application. As you can see, these commands allow you to create your project or generate an angular component or modify an existing component. In the next chapter, we are going to learn about Angular 12 testing