Click here to Skip to main content
14,643,636 members
Articles » Web Development » Client side scripting » General
Posted 5 Sep 2015


26 bookmarked

AngularJS 2.0 Getting Started with Visual Studio

Rate this:
4.68 (26 votes)
Please Sign up or sign in to vote.
4.68 (26 votes)
5 Sep 2015CPOL
In this tip, we will discuss how to setup Angular 2.0 in Visual Studio and write a very basic “Todo” application.


As you already know, Angular is a developing platform with modern web standards. Angular 2.0 is the latest version which is still in the developer preview (2015 Aug). There is considerable difference in Angular 2.0 and 1.X.

Step 1

First you have to install nodejs which is the runtime builder for JavaScript. Use the following link to install it.

Then install TypeScript to Visual Studio. It will compile your code to plain JavaScript. Use the following link to install it.

Step 2

Open your Visual Studio and go to File =>New =>project. Then select “HTML Application with TypeScript” as shown in the below image:

Image 1

Step 3

Open the command prompt in your project folder. To do that, open your project folder and Right click with holding Shift key and select “Open command window here”. Run the below commands to get TypeScript definitions to Angular.

npm install tsd
tsd query angular2 es6-promise rx rx-lite --action install 

Then, go to your Solution explorer and click “Show all files”. It will be as the below image. Include “typings” folder to the project.

Image 2

Step 4

Right click on the project and go to the properties. Then select “TypeScript Build” tab and change module system property to “CommonJs” as shown in the below image. Keep other settings as default.

Image 3

One more thing to do before coding. Again go to the project folder and open “TodoSampleApp” CSPROJ file with Notepad. (not the Visual Studio project file. Consider the file type before open.) Add the below property group to this file.


Now file will be as below image:

Image 4

Step 5

Now you have completed the project setup steps. You just need to code your app now.

Replace your index.html with the following code:

<!DOCTYPE html>
    <title>Angular 2</title>
    <meta charset="utf-8" />

    <script src=""></script>
    <script src=""></script>
    <script src=""></script>

Replace your app.ts code with the below code:

import {Component, View, bootstrap, NgFor} from 'angular2/angular2';

    selector: "my-app",

    templateUrl: 'mainForm.html',
    directives: [NgFor]

class TodoAppComponent {

    todos: Array<Object>;

    constructor() {
        this.todos = [{ text: "Try Second", done: true }] 

    get() {
        return this.todos;

    add($event, newtodo) {

        if ($event.which === 13) {
            this.todos.unshift({ text: newtodo.value, done: false });
            newtodo.value = ''


    markAsDone(todo) {
        todo.done = !todo.done;


Add html file and rename as “mainForm” and replace it with the below code:

<h1>Hellow Angular 2</h1>

<div style="text-align:center">
    <input type="text"

           placeholder="New todo.."


    <tr *ng-for="#todo of get()">
            <input type="checkbox" name="vehicle" checked="{{todo.done}}">

Congratulations …!!! You just completed your todoApp.

There are many resources available for Angular 2.0 theory in the community. So if you are still new to this, please try to understand the basic concepts first because I have not covered the basic concepts. This is just a small practical session.

In the next tip, we will study a little more complex sample app with “appInjector” in Angular 2.0.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Technical Lead ISM APAC (Pvt) Ltd
Sri Lanka Sri Lanka
No Biography provided

Comments and Discussions

Questionnpm install tsd - Visual Studio 2015 Pin
suhel_khan28-Nov-16 19:47
professionalsuhel_khan28-Nov-16 19:47 
QuestionIn Step 3 this command is not working: "tsd query angular2 es6-promise rx rx-lite --action install " Pin
Rajesh_Pa29-Aug-16 23:29
MemberRajesh_Pa29-Aug-16 23:29 
QuestionNodeJS is the "runtime builder for JavaScript"? Pin
Rick Shaw4-Jul-16 22:17
MemberRick Shaw4-Jul-16 22:17 
QuestionStop working after any change Pin
BMicka12-Apr-16 20:55
MemberBMicka12-Apr-16 20:55 
Questionhave you tried with vs2013? which version you used for this application? Pin
Mansoor Alikhan K27-Dec-15 22:23
MemberMansoor Alikhan K27-Dec-15 22:23 
QuestionDoesn't work in VS 2012 - missing on step 4 the 'Typescript build' option under properties Pin
Member 104533023-Dec-15 10:15
MemberMember 104533023-Dec-15 10:15 
QuestionWorks only with html with typescript Pin
Jeevanandan J22-Dec-15 19:00
MemberJeevanandan J22-Dec-15 19:00 
QuestionDebugging in VS Pin
commerce@jant.de30-Nov-15 3:31
Membercommerce@jant.de30-Nov-15 3:31 
QuestionError angular/angular2 Pin
piermorosini15-Nov-15 22:13
Memberpiermorosini15-Nov-15 22:13 
AnswerRe: Error angular/angular2 Pin
piermorosini16-Nov-15 8:02
Memberpiermorosini16-Nov-15 8:02 
GeneralRe: Error angular/angular2 Pin
iceborg21-Dec-15 4:28
Membericeborg21-Dec-15 4:28 
BugError, cannot find module. Pin
Bonum Signum1-Nov-15 6:16
MemberBonum Signum1-Nov-15 6:16 
QuestionGetting Error: Cannot find module 'angular2/angular2' Pin
Nav Ali18-Oct-15 12:10
MemberNav Ali18-Oct-15 12:10 
QuestionCan't run in IE 11 Pin
kkssccyycc14-Sep-15 8:35
Memberkkssccyycc14-Sep-15 8:35 
Questionif change angular2 from /2.0.0-alpha.28/ to /2.0.0-alpha.37/ Pin
kkssccyycc14-Sep-15 8:11
Memberkkssccyycc14-Sep-15 8:11 
GeneralGood article. Pin
Member 119728729-Sep-15 19:15
MemberMember 119728729-Sep-15 19:15 
SuggestionNot really for beginners Pin
harsimranb8-Sep-15 8:21
Memberharsimranb8-Sep-15 8:21 
GeneralRe: Not really for beginners Pin
Thinira8-Sep-15 18:49
MemberThinira8-Sep-15 18:49 
QuestionNeeds more Pin
Ed Bouras8-Sep-15 5:19
MemberEd Bouras8-Sep-15 5:19 
BugTSD Pin
resnik8-Sep-15 4:31
Memberresnik8-Sep-15 4:31 
AnswerRe: TSD Pin
Laz_X9-Sep-15 15:33
MemberLaz_X9-Sep-15 15:33 
GeneralRe: TSD Pin
resnik10-Sep-15 16:15
Memberresnik10-Sep-15 16:15 
GeneralRe: TSD Pin
Jeevanandan J22-Dec-15 18:51
MemberJeevanandan J22-Dec-15 18:51 
GeneralMy vote of 4 Pin
Abhishek Kumar Goswami8-Sep-15 3:13
professionalAbhishek Kumar Goswami8-Sep-15 3:13 
Good one

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.