Angular 2 Hello world example

Angular 2 Hello world example

There are different ways to start with angular 2. The most simple and easy way is to use Angular CLI. You can get more info at the official site of angular CLI. Here are the steps that you should follow

1) Install node.js

In order to start with Angular CLI, one need to have nodejs installed on your local machine. You can download and install the latest version of nodejs from its official site.

2) Install typescript

Angular 2 is written in typescript, it is advisable to use typescript to develop any application. Moreover Angular CLI is in written in typescript, which gives overall advantage of using Typescript. It can be installed on local by executing command npm install -g typescript on command prompt.

Note : You can verify version of typescript using tsc -v command.

3) Install Angular CLI

Install Angular CLI globally using command npm install -g @angular/cli. It will take some time (until you finish your coffee) to install on your local machine. Once installation has finished, you can check its version using command ng -v.

4) Create Hello World application.

After successful completion of above steps, you’re ready to jump start with your first Angular 2 application. Navigate to the folder on your local drive where you have created workspace for your first application and open command prompt in that specific folder location. Now using the command ng new your_application_name, you would be able create first Angular 2 application . For example, I have created application code2succeed as ng new code2succeed. This command takes few minutes as it copies all dependencies on your local machine.

After successful completion of this command, you are all set to run your first Angular 2 application. You can open this application in any of your favorite code editor.

5) Run the application

Use command cd your_application_name to enter inside your application folder. Now use command ng serve –open which will open your application in default browser. You will get below output 

Stay tuned for more updates and tutorials !!!

Leave a Reply

Your email address will not be published. Required fields are marked *