include ../../../../_includes/_util-fns :markdown Let's start from zero and build a simple Angular 2 application in TypeScript. .callout.is-helpful header Don't want TypeScript? :markdown Although we're getting started in TypeScript, you can also write Angular 2 apps in JavaScript and Dart by selecting either of those languages from the combo-box in the banner. :markdown We'll do it in short steps 1. Install the prerequisites for Angular TypeScript development 1. Create the application project structure 1. Install the npm packages our app needs 1. Prepare for TypeScript compilation 1. Create an **`index.html`** 1. Write the root component for our application in **`app.ts`** 1. Bootstrap the app 1. Compile the TypeScript to JavaScript 1. Run it .l-main-section :markdown ## Prerequisites We'll need a base of tools for all of our application development. We'll only install these once starting with [**node** and **npm**](https://docs.npmjs.com/getting-started/installing-node "Installing Node.js and updating npm"). Now use npm in a terminal (or Windows/Linux command line) to install the **TypeScript compiler** globally pre.prettyprint.lang-bash code npm install -g typescript :markdown Use npm again to install the [**tsd package manager**](https://www.npmjs.com/package/tsd "TSD Package Manager") so we can download TypeScript type definitions files ("`.d.ts`" files) from the [DefinitelyTyped](http://definitelytyped.org/) repository. pre.prettyprint.lang-bash code npm install -g tsd :markdown Install a node **static server** to serve our application. We'll use **live-server** for this example because it performs a live reload by default and it's fun to watch the browser update as we make changes. pre.prettyprint.lang-bash code npm install -g live-server .l-sub-section :markdown Our success depends upon installing compatible versions of these tools. Confirm your version numbers in a terminal window with these commands: table tr th Command th Versions tr td code node -v td 0.10.* - 0.12.*   But not 4.0.0 !!! tr td code npm -v td 2.11+ (3.* is fine) tr td code tsc -v td 1.6+ tr td code tsd --version td 0.6.5+ tr td code live-server -v td 0.8+ .l-main-section :markdown ## Create the application project structure Create a new folder to hold our application project, perhaps like this: ``` mkdir angular2-getting-started cd angular2-getting-started ``` :markdown We'll refer to this as our application's **root folder**. Now add a sub-folder - `src` - to hold project source code and a sub-sub-folder - `src/app` - to hold to hold the application source code. In OS/X and Linux: pre.prettyprint.lang-bash code mkdir src/app :markdown In Windows: pre.prettyprint.lang-bash code mkdir src\app :markdown Our project folders should look like this. ``` angular2-getting-started ├── src └──── app ``` .l-main-section :markdown ## Install npm packages Our application will need some 3rd party JavaScript files: >***angular.js***, the Angular 2 library. >***system.js***, a third-party open-source library that adds module loading functionality to our browser. >***traceur-runtime.js*** to transpile the TypeScript-generated JavaScript into the version of Javascript our browser understands (the version known as "ES5"). We'll install these package with `npm` and create an npm **`package.json`** configuration file that to maintain future packages as our application evolves. In a terminal window, go to the **root** folder and type: ``` npm init -y npm install --save angular2@2.0.0-alpha.37 systemjs@0.19.2 ``` `npm` produced a `node_modules` folder that holds these packages and other packages that *they* require. The essence of our `package.json` should look like this: +makeJson('gettingstarted/ts/package.json', { paths: 'name, version, dependencies '}) .l-main-section :markdown ## Prepare for TypeScript Compilation ### Add links to TypeScript definition files We prefer writing TypeScript apps in editors that understand TypeScript, such as [Visual Studio Code](https://code.visualstudio.com/) and [Web Storm](https://www.jetbrains.com/webstorm/features/). Such editors improve the development experience by checking type information and displaying API documentation ("intellisense") based on TypeScript definition files (`.d.ts`). The definition files we need are included in the npm packages we just installed. We'll use the [**tsd package manager**](https://www.npmjs.com/package/tsd "TSD Package Manager") to generate an *aggregate TypeScript definition file*, **`tsd.d.ts`**, that holds links to the type definition files in those packages. In the ***root* folder** enter the following command pre.prettyprint.lang-bash code tsd link --config src/tsd.json :markdown That produces a new **`src/typings`** folder with the **`tsd.d.ts`** file. Now Angular type checking and intellisense lights up automatically as we write our app in the Visual Studio Code and Web Storm editors. Check your editor's documentation for instructions on using the `tsd.d.ts` file. ### Add the TypeScript configuration file We need to tell that editor how to interpret our TypeScript which we do with a configuration file named **`tsconfig.json`**. This configuration file also simplifies the TypeScript compilation command that we'll run very soon. **Change to the `src` folder and create a `tsconfig.json`** file with the following content: +makeJson('gettingstarted/ts/src/tsconfig.json', null, 'tsconfig.json') :markdown Our project should now look like this: ``` angular2-getting-started ├── node_modules ├── src │ ├── app │ ├── typings │ │ ├── tsd.d.ts │ ├── tsconfig.json └── package.json ``` .l-main-section :markdown ## Create an `index.html` While in the **`src`** directory and add a new `index.html` file with the following HTML +makeExample('gettingstarted/ts/src/index.html', null, 'index.html', {pnk: [/(angular2\.dev\.js)/, /(system\.src\.js)/, /(traceur-runtime\.js)/]}) .l-sub-section :markdown Notice in the `
` element that we're loading the scripts we installed earlier with npm. There's an element called `