Angular Basic/Important Commands
Angular Commands
Note:- First come inside work space of your project.
From Angular 14 onwards for building Angular project
ng build --configuration production
Npm Version Command
npm --version
Node Version Command
node --version
Angular Version Command
Shows Angular CLI version. It is stated below −
ng version
To create an application in Angular,
Syntax − ng new <project-name>
Ex: To create CustomerApp run below command
ng new CustomerApp
For creating component
Syntax −
ng g c
Ex:
F:\Angular Training Sah\Angular Project\backend> ng g c <component_name>
CREATE src/app/test/test.component.html (19 bytes)
CREATE src/app/test/test.component.spec.ts (585 bytes)
CREATE src/app/test/test.component.ts (268 bytes)
CREATE src/app/test/test.component.scss (0 bytes)
UPDATE src/app/app.module.ts (1633 bytes)
Note:- --skip-tests option to avoid generating test file i.e. .component.spec.ts
Ex:
F:\Angular Training Sah\Abhishek Angular LiveProject\backend> ng g c test --skip-tests
Angular command to run and open the project
Syntax −
ng serve --open
Angular command to Create Class
Syntax −ng generate class <class_name>
Ex: If you want to create a customer class, then type the below command −
ng g class Customer
Create a pipe
Pipes are used for filtering the data. It is used to create a custom pipe in Angular. It is defined below −
Syntax −
Syntax −
ng g pipe <pipe-name>
If you want to create a custom digit counts in a pipe, then type the below command −
ng g pipe DigitCount
Create a directive
It is used to create a new directive in Angular. It is defined below −
Syntax −
ng g directive <directive-name>
If you want to create a UnderlineText directive, then type the below command −
ng g directive UnderlineText
Create a module
It is used to create a new module in Angular. It is defined below −
Syntax −
ng g module <module-name>
If you want to create a user information module, then type the below command −
ng g module Userinfo
Create an interface
It is used to create an interface in Angular. It is given below −
Syntax −
ng g interface <interface-name>
If you want to create a customer class, then type the below command −
ng g interface CustomerData
Create a service
It is used to create a service in Angular. It is given below −
Syntax −
ng g service <service-name>
If you want to create a customer class, then type the below command −
ng g service CustomerService
Create an enum
It is used to create an enum in Angular. It is given below −
Syntax −
ng g enum <enum-name>
If you want to create a customer class, then type the below command −
ng g enum CustomerRecords
Build command
It is used to compile or build your angular app. It is defined below −
Syntax −
ng build
Help command
It lists out available commands and their short descriptions. It is stated below −
Syntax −
ng help
Test command
Runs unit tests in a project. It is mentioned below −
Syntax −
ng test
Update command
Updates your application and its dependencies. It is given below −
Syntax −
ng update
Command For Creating Module
It is used to create a new generic NgModule definition in the given or default project.
Syntax −
ng generate module <name> [options]
ng g module <name> [options]
ng e2e Command
It is used to build and serve an Angular app, then runs end-to-end tests using Protractor.
Syntax −
ng e2e <project> [options]
ng e <project> [options]
It must be executed from within a workspace directory. When you don't specify the project name, it executes for all projects.
Parameter Explanation:
<project>: It specifies the name of the project you want to build. It can be an app or a library.
Comments
Post a Comment