This is the second part of the series “Learn Angular 9 From Scratch”. In this post, we will learn how to create a new Angular application using Angular Command Line Interface i.e. Angular CLI. We will also learn about two new Angular commands i.e. ng new and ng serve. We will also test our new Angular application on localhost.
Create a New Application
- Open command prompt as an administrator
- When you open the command prompt, you will be inside the directory C:\WINDOWS\System 32>
- Change directory / CD into the folder where you want to create a new Angular application (see screenshot 1) e.g. to change the current directory to D drive, type D: and hit Enter.
- Run the command: ng new myapp // change ‘myapp’ to whatever name you want for your application
- Now Angular CLI will ask two questions i.e. would you like to add Angular routing? (I have selected Yes, because we will implement routing in our application) and which stylesheet format would you like to use? (I have selected CSS but you can select other format as well) [see screenshot 1]
- After the confirmations, Angular CLI will install all necessary packages and their dependencies and will create a new Angular application inside the folder ‘myapp’
Test the Application
- Change directory / CD into folder ‘myapp’ e.g. cd myapp
- Run the command: ng serve
- Angular CLI will compile the application code and will serve the application on http://localhost:4200 (see screenshot 2)
- Now you can test the application on http://localhost:4200 (see screenshot 3)
In the next post, we will learn what are the components and how to create components in an Angular application using Angular CLI. Stay tuned!