These commands are use for create a project , project component, services, models etc in angular. The list of all command and there information are availabel here.
Setup CLI
We need to install CLI first of all open command prompt and write down given command . It will automaticaly install Angular CLI in system. Before this you need Node.js Installed in your system. Go to node official website simply downlod the installer and run on your system. After that this command will work for you.
npm install @angular/cli -g
Create new angular projects
ng new: Command
This command is user to create a new project with angular CLI.
ng new project name
Example
ng new project-1
--dry run instruction for CLI
Simply when we don’t know what a command do in our system. We can use –dry run instruction with command it will show its working in console but don’t do anything in system.
Example
ng new project –dry run
--skip-install instruction
This instruction is givern for that when you don’t want to install external dependencies right after the creation of new project.
Example
ng new project-1 --skip-install
You can install all skiped dependencies also using npm install command on your root folder
npm install
--skip-tests instruction
When we create project using CLI it create a .spec.ts file automatcly. It do same for the components also. This file required only for testing purpose sometime you don’t want it to generate to do so we use this instruction along with the command
Example
ng new project-1 --skip-tests
This command will create a angular project. It will create all files expact .spec.ts file. By using this you can save a lot of space on your drive.
Generate component using angular CLI
In a angular project there is a lot of section of project which is called components. It depends on each other. We
generate these components using CLI later we manage to communicate them each other to get result.
To generate these components we use these command
ng generate component [component-name]
Example
ng generate component page-1
We can minimize these code like
ng g c page-1
here g for generate c for component
ng serve
This command is use for run project for example go to your project root folder and type this command in terminal
ng serve
It will compile your project and run on default browser.
Ng build
This command us use to creat build for deploy your project on web-server.
As you know angular CLI create devide project into components, serveces, pipes, and models. We can not deploye all
these filse same as it is.
Angular CLI create a finel build of project where all compiled code are stored.
To create this build we use ng build command. By default CLI store build in dist folder. To create buld you have to go
in your project root folder and run this command in terminal
Example
ng build
It will compile your project and stored in dist folder. But build is not fully finel build this is in development
mode it still use some development time variable.
To create a fully finel build we use –prod instructin with build command.
Example
ng build --prod
Comments
Post a Comment