Tuesday, 29 August 2017

Angular2 CLI

The Angular CLI is a command-line interface tool that you use to initialize, develop, scaffold, and maintain Angular applications directly from a command shell.

Verify CLI
Before moving to Angular CLI commands, we have to ensure that Angular CLI is installed on your machine. If it is installed, you can verify it by using the command − ng version

If CLI is not installed, then use the below command to install it.

npm install -g @angular/cli

To create, run an application in Angular, use the below syntax 

ng new [PROJECT-NAME]
cd [PROJECT-NAME]
ng serve

Navigate to . http://localhost:4200/ The app will automatically reload if you change any of the source files.

You can configure the default HTTP host and port used by the development server with two command-line options :

ng serve --host 0.0.0.0 --port 4201

Generating Components, Directives, Pipes and Services
You can use the ng generate (or just ng g) command to generate Angular components:


ng generate component my-new-component
ng g component my-new-component //using the alias

//components support relative path generation
//if in the directory src/app/feature/ and you run
ng g component new-cmp

//your component will be generated in src/app/feature/new-cmp 

You can find all possible blueprints in the table below:
scaffoldusage
Componentng g component my-new-component
Directiveng g directive my-new-directive
Pipeng g pipe my-new-pipe
Serviceng g service my-new-service
Classng g class my-new-class
Guardng g guard my-new-guard
Interfaceng g interface my-new-interface
Enumng g enum my-new-enum
Moduleng g module my-module
angular-cli will add reference to componentsdirectives and pipes automatically in the app.module.ts. If you need to add this references to another custom module, follow this steps:
  1. ng g module new-module to create a new module
  2. call ng g component new-module/new-component
This should add the new componentdirective or pipe reference to the new-module you've created.
Documentation
The documentation for the Angular CLI is located in this repo's wiki.




0 comments:

Post a Comment

Topics

ADFS (1) ADO .Net (1) Ajax (1) Angular (47) Angular Js (15) ASP .Net (14) Authentication (4) Azure (3) Breeze.js (1) C# (49) CD (1) CI (2) CloudComputing (2) Coding (8) CQRS (1) CSS (2) Design_Pattern (7) DevOps (4) DI (3) Dotnet (10) DotnetCore (19) Entity Framework (4) ExpressJS (4) Html (4) IIS (1) Javascript (17) Jquery (8) Lamda (3) Linq (10) microservice (4) Mongodb (1) MVC (46) NodeJS (8) React (10) SDLC (1) Sql Server (32) SSIS (3) SSO (1) TypeScript (3) UI (1) UnitTest (2) WCF (14) Web Api (16) Web Service (1) XMl (1)

Dotnet Guru Archives