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 syntaxng 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:
angular-cli will add reference to
components
, directives
and pipes
automatically in the app.module.ts
. If you need to add this references to another custom module, follow this steps:ng g module new-module
to create a new module- call
ng g component new-module/new-component
This should add the new
Documentationcomponent
, directive
or pipe
reference to the new-module
you've created.The documentation for the Angular CLI is located in this repo's wiki.
0 comments:
Post a Comment