Angular CLI
Angular CLI is a command line tool that can aid in creating new Angular projects from scratch or adding various elements to an existing Angular application. you’re not required to use Angular CLI to develop an Angular application, but its many features can highly improve the quality of your code and save you a lot of time along the way.
In order to install Angular CLI, the following should be installed in the development environment:
– Installing Angular CLI
$ npm install -g @angular/cli
– Creating a New Angular Application
ng init
: create a new application in the current directoryng new
: create a new directory and runng init
inside the new directory.
$ ng new my-app
– Run Application
Change to the my-app
directory and run the following:
$ ng serve
Then open a browser and point it to http://localhost:4200
-Create A Class (ts file)
To create a new class, run the following:
$ ng g class my-class-a
This will create a file called my-class-a.ts under the src/app directory.
– Create A Component
To create a new component, run the following:
$ ng g component my-component-a
- create a directory called
my-component-a
undersrc/app
directory - generate four files
- my-component-a.component.css
- my-component-a.component.html
- my-component-a.component.spec.ts
- my-component-a.component.ts
- modifies
app.module.ts
file, addedMyComponentAComponent
to declarations