You are reading the article A Complete Guide To The Angular Cli updated in September 2023 on the website Chivangcangda.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested October 2023 A Complete Guide To The Angular Cli
Introduction to Angular CLIAngular CLI is basically a Command Line Interface that provides the capability to utilize the Command Window to execute and build the basic Angular application structure just by writing down the CLI Commands which Angular understands and interprets the action to be taken on each command. Angular CLI is compatible with all higher and major versions of Angular (NOT AngularJS).
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
How do Angular CLI works?The first step to start working with Angular CLI is to install the CLI package from NPM (Node Package Manager).
npm install -g @angular/cliThis command works just like any other NPM command where for installing external dependency, we run.
Code:
npm install dependencyNameThis module of Angular CLI will let you set up your application from scratch instead of creating each component, service, module, and HTML and building the entire application manually. It becomes a bit tedious and time-consuming work when we do it manually. Creating projects from scratch, generating components, and services, skipping the test, Running the application on the browser, and many more such features can be achieved from Angular Command Line Interface (CLI).
Angular CLI CommandsLet’s see some examples and usage of Angular CLI commands.
All in One Software Development Bundle (600+ Courses, 50+ projects)Programming Languages Training (41 Courses, 13+ Projects, 4 Quizzes)
Building a basic application on Angular Framework using Angular CLI.
Code:
npm install -g @angular/cli ng new basic-demo-applicationThe Angular CLI comes into the picture as soon as ng is read; it traverses to the following command, which is new, so now CLI knows that it has to create a new Angular Application and the 3rd parameter is the name of the application, it can be any lower case name of your application which will have all files and modules inside this basic-demo-application folder.
A few basic questions will prompt you while CLI is building a new application, like which style sheet should be used (CSS, SCSS), would you like to add Angular Routing and a few others.
This is not it; the ng new command has many more options that can be used to achieve additional project requirements.
Hosting Angular Application on BrowserGiven below shows hosting the angular application on the browser:
Code:
npm install -g @angular/cli ng new basic-demo-application cd basic-demo-application ng serveOutput:
To host your application on the browser window, once the application is created using ng new CLI command, go inside the basic-demo-application directory and run the ng serve CLI command. This will start listening to your application on port 4200, and you can quickly test your application locally while developing. The ng serve command lets you build, rebuild after changes, and serve your application.
Generating New Components/ Services/Modules with Angular ApplicationGiven below shows generating of new components/ services/ modules with the angular application:
Generate a new component.
ng generate component component-name
Generate a new basic application.
ng generate application application-name
Generate a new directive.
ng generate directive directive-name
Generate a new interface.
ng generate interface interface-name
Adding a new library to the project.
ng generate library library-name
Create a new module inside the Angular application.
ng generate module module-name
Create an enum inside the Angular application.
ng generate enumenum-name
Create an appShell inside the Angular application.
ng generate appShellappShell-name
Create a pipe inside the Angular application.
ng generate pipepipe-name
Creating or adding any new construct like components, services, or modules within the angular application gets too tedious process if you need to do that manually to overcome this work; Angular CLI has another CLI command which helps you to generate new services, directives, component, application, library, class, interface, etc. All these constructs of ng generate come along with additional option tags such as defaults, dryRun, force, help, flat, interactive, etc. This lets the user decide on whether there is any need for an additional folder, overwrites existing files, etc. The options tag should be used with – as a prefix.
Skipping to Create Test Files in Angular ApplicationGiven below shows the skipping to create test files in angular application:
This Command is very useful when you are just a Rookie in Angular programming and want to know and learn about the basic repo building and do not need the test files to be created in our demo projects as those are just for your understanding or, at times we want just to debug a piece of code in a new project and don’t need the test files to be created. This is exactly where –skip-tests come into the picture; this CLI command will not create the .spec files in your Angular application.
1. Without skipping testng new basic-demo-application
2. Use Skip Test while creating Angular Projectng new basic-demo-skip-test-application –skip-tests
Search for Keywords on Browser using Angular DocumentationGiven below shows a search for keywords on the browser using angular documentation:
Code:
ng doc keyword ng doc ActivatedRouteOutput:
The ng doc command is used when you want to browser for any particular keyword from the chúng tôi documentation and get knowledge and understanding about any specific keyword of Angular. Once you execute the command, the default browser opens, displaying the chúng tôi documentation site’s details about that keyword.
Conclusion Recommended ArticlesThis is a guide to Angular CLI. Here we have discussed the introduction, working, commands, hosting the angular application on the browser, generating new components/ services/modules, skipping to create test files, and search for keywords on the browser using angular documentation. You may also have a look at the following articles to learn more-
You're reading A Complete Guide To The Angular Cli
Update the detailed information about A Complete Guide To The Angular Cli on the Chivangcangda.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!