|
1 | 1 | .callout.is-helpful
|
2 |
| - header Angular is still unpackaged and in alpha |
| 2 | + header Angular is in alpha |
3 | 3 | p.
|
4 | 4 | This quickstart does not
|
5 |
| - reflect the final build process for Angular. The following setup is for those who |
| 5 | + reflect the final development process for Angular. The following setup is for those who |
6 | 6 | want to try out Angular while it is in alpha.
|
7 | 7 |
|
8 | 8 | // STEP 1 - Create a project ##########################
|
9 | 9 | .l-main-section
|
10 | 10 | h2#section-create-project 1. Create a project
|
11 | 11 |
|
12 | 12 | p.
|
13 |
| - The goal of this quickstart is to create a component that renders "Hello Alice" to the page. |
14 |
| - To get started, create a new directory. |
| 13 | + This quickstart shows how to write your Angular components in TypeScript. You could instead choose |
| 14 | + another language such as Dart, ES5, or ES6. |
15 | 15 |
|
16 |
| - pre.prettyprint |
17 |
| - code. |
18 |
| - mkdir angular2_quickstart |
19 |
| - cd angular2_quickstart |
20 |
| - |
21 |
| -// STEP 2 - Add the es6-shim ########################## |
22 |
| -.l-main-section |
23 |
| - h2#section-add-es6-shim 2. Clone the quickstart repository |
24 |
| - |
25 |
| - p Within your project, clone the quickstart repository: |
| 16 | + p. |
| 17 | + The goal of this quickstart is to write a component in TypeScript that prints a string. |
| 18 | + To get started, clone the TypeScript quickstart repository: |
26 | 19 |
|
27 | 20 | pre.prettyprint
|
28 |
| - code git clone https://github.com/angular/quickstart.git |
| 21 | + $ git clone https://github.com/angular/ts-quickstart.git |
| 22 | + $ cd ts-quickstart |
29 | 23 |
|
30 | 24 | p.
|
31 | 25 | For the sake of this quickstart we recommend using the
|
32 |
| - <a href="https://github.com/angular/quickstart"> <code>quickstart</code> GitHub repository</a>. |
33 |
| - This repository provides a faster start than building from <code>npm</code>. This repository includes Angular and dependencies to compile ES6 in incompatible browsers. |
34 |
| - |
35 |
| - .l-sub-section |
36 |
| - h3 ES6, AtScript, and the es6-shim |
| 26 | + <a href="https://github.com/angular/ts-quickstart"> <code>quickstart</code> GitHub repository</a>. |
| 27 | + This repository provides a faster start than building from <code>npm</code>. |
| 28 | + This repository includes the Angular distribution and type definitions for TypeScript. |
37 | 29 |
|
38 |
| - h4 AtScript |
39 |
| - p. |
40 |
| - Angular is built with <strong>AtScript</strong>. AtScript is an extension of ES6 (ECMAScript 6), the new specification |
41 |
| - of the JavaScript language. This quickstart features AtScript, but you can write Angular in ES5 or ES6 as well. |
| 30 | +// STEP 2 - Start the TypeScript compiler ########################## |
| 31 | +.l-main-section |
| 32 | + h2#start-tsc 2. Run the TypeScript compiler |
42 | 33 |
|
43 |
| - h4 ES6 |
44 |
| - p. |
45 |
| - AtScript compiles to <strong>ES6</strong>, which is not widely supported in all browsers today. |
46 |
| - The <code>es6-shim.js</code> file allows you to use ES6 or AtScript in the browser. |
| 34 | + p. |
| 35 | + Since the browser doesn't understand TypeScript code, we need to run a compiler to translate |
| 36 | + your code to browser-compliant JavaScript as you work. This quickstart uses the TypeScript |
| 37 | + compiler in <code>--watch</code> mode, but it is also possible to do the translation in the browser as files |
| 38 | + are loaded, or configure your editor or IDE to do it. |
| 39 | + p. |
| 40 | + The repository includes a file <code>tsconfig.json</code>. |
| 41 | + Many tools — including the TypeScript compiler — |
| 42 | + know to read this file so we don't need to configure them or add command-line options. |
47 | 43 |
|
48 |
| - h4 es6-shim |
49 |
| - p. |
50 |
| - The <strong>quickstart</strong> repository includes <code>es6-shim.js</code>. |
51 |
| - The es6-shim.js file includes dependencies (such as Traceur) needed to compile |
52 |
| - ES6 in the browser. Traceur is an ES6 compiler that transpiles ES6 to ES5 code. |
| 44 | + pre.prettyprint |
| 45 | + # We need to use an unreleased version of TypeScript |
| 46 | + $ npm install -g mhegazy/typescript#v1.5-beta |
| 47 | + $ tsc --watch |
53 | 48 |
|
54 | 49 | // STEP 3 - Import Angular ##########################
|
55 | 50 | .l-main-section
|
56 | 51 | h2#section-transpile 3. Import Angular
|
57 | 52 |
|
58 | 53 | p.
|
59 | 54 | Create two files, <code>index.html</code> and
|
60 |
| - <code>app.es6</code>, both at the root of the project: |
| 55 | + <code>app.ts</code>, both at the root of the project: |
61 | 56 |
|
62 | 57 | pre.prettyprint
|
63 |
| - code. |
64 |
| - touch index.html |
65 |
| - touch app.es6 |
66 |
| - |
67 |
| - .alert.is-helpful. |
68 |
| - The <code>.es6</code> extension signifies that the file uses ES6 syntax. If your editor doesn't |
69 |
| - support syntax highlighting for .es6, use .js. |
| 58 | + $ touch index.html |
| 59 | + $ touch app.ts |
70 | 60 |
|
71 |
| - p Inside of <code>app.es6</code>, import the required modules from Angular: |
| 61 | + p Inside of <code>app.ts</code>, import the type definitions from Angular: |
| 62 | + pre.prettyprint |
| 63 | + code /// <reference path="typings/angular2/angular2.d.ts" /> |
72 | 64 |
|
73 |
| - pre.prettyprint.linenums |
74 |
| - code import {Component, Template, bootstrap} from 'angular2/angular2'; |
| 65 | + p Now your editor should be able to complete the available imports: |
| 66 | + pre.prettyprint |
| 67 | + code import {Component, View, bootstrap} from 'angular2/angular2'; |
75 | 68 |
|
76 | 69 | p.
|
77 |
| - The above import statement uses ES6 module syntax to import three modules from Angular. |
78 |
| - These modules load at runtime. |
| 70 | + The above import statement uses ES6 module syntax to import three symbols from the Angular module. |
| 71 | + The module will load at runtime. |
79 | 72 |
|
80 | 73 |
|
81 | 74 | // STEP 4 - Create a component ##########################
|
|
88 | 81 | that has an HTML tag named <strong><code><my-app></code></strong>.
|
89 | 82 |
|
90 | 83 | p.
|
91 |
| - A component consists of two parts, the <strong>annotation section</strong> |
92 |
| - and the <strong>component controller</strong>. |
| 84 | + A component consists of two parts, the <strong>component controller</strong> |
| 85 | + which is an ES6 class, and the <strong>decorators</strong> which tell Angular |
| 86 | + how to place the component into the page. |
93 | 87 |
|
94 | 88 | pre.prettyprint.linenums
|
95 | 89 | code.
|
|
102 | 96 | })
|
103 | 97 | // Component controller
|
104 | 98 | class MyAppComponent {
|
| 99 | + name: string; |
| 100 | + |
105 | 101 | constructor() {
|
106 | 102 | this.name = 'Alice';
|
107 | 103 | }
|
|
134 | 130 | h3 The template and the component controller
|
135 | 131 |
|
136 | 132 | p.
|
137 |
| - The component controller is the backing of the component's template. A component |
138 |
| - controller uses ES6 <code>class</code> syntax. |
| 133 | + The component controller is the backing of the component's template. This component |
| 134 | + controller uses TypeScript <code>class</code> syntax. |
139 | 135 |
|
140 | 136 | pre.prettyprint.linenums
|
141 | 137 | code.
|
142 | 138 | class MyAppComponent {
|
| 139 | + name: string; |
143 | 140 | constructor() {
|
144 | 141 | this.name = 'Alice';
|
145 | 142 | }
|
|
163 | 160 | h2#section-transpile 5. Bootstrap
|
164 | 161 |
|
165 | 162 | p.
|
166 |
| - At the bottom of <code>app.es6</code>, call the <code>bootstrap()</code> function |
| 163 | + At the bottom of <code>app.ts</code>, call the <code>bootstrap()</code> function |
167 | 164 | to load your new component into its page:
|
168 | 165 |
|
169 | 166 | pre.prettyprint.linenums
|
|
182 | 179 | h2#section-angular-create-account 6. Declare the HTML
|
183 | 180 |
|
184 | 181 | p.
|
185 |
| - Inside the <code>head</code> tag of <code>index.html</code>, include the <code>es6-shim.js</code> file. |
186 |
| - (The es6-shim code must load before any application code.) |
187 |
| - Then instantiate the <code>my-app</code> component in the <code>body</code>. |
| 182 | + Inside the <code>head</code> tag of <code>index.html</code>, |
| 183 | + include the traceur-runtime and the Angular bundle. |
| 184 | + Instantiate the <code>my-app</code> component in the <code>body</code>. |
188 | 185 |
|
189 | 186 | pre.prettyprint.linenums
|
190 | 187 | code.
|
191 | 188 | <!-- index.html -->
|
192 | 189 | <html>
|
193 | 190 | <head>
|
194 | 191 | <title>Angular 2 Quickstart</title>
|
195 |
| - <script src="/quickstart/dist/es6-shim.js"></script> |
| 192 | + <script src="https://github.jspm.io/jmcriffey/bower-traceur-runtime@0.0.87/traceur-runtime.js"></script> |
| 193 | + <script src="bundle/angular2.dev.js"></script> |
196 | 194 | </head>
|
197 | 195 | <body>
|
198 | 196 |
|
199 |
| - <!-- The app component created in app.es6 --> |
| 197 | + <!-- The app component created in app.ts --> |
200 | 198 | <my-app></my-app>
|
201 | 199 |
|
202 | 200 | </body>
|
|
209 | 207 |
|
210 | 208 | p.
|
211 | 209 | The last step is to load the module for the <code>my-app</code> component.
|
212 |
| - To do this, we'll use the System library, which is included in the quickstart repository. |
| 210 | + To do this, we'll use the System library. |
213 | 211 |
|
214 | 212 | .l-sub-section
|
215 | 213 | h3 System.js
|
|
219 | 217 | adds ES6 module loading functionality to browsers.
|
220 | 218 |
|
221 | 219 | p.
|
222 |
| - Add the following module-loading code to <code>index.html</code>: |
| 220 | + Add the System.js dependency in the <code><head></code> tag: |
223 | 221 |
|
224 | 222 | pre.prettyprint.linenums
|
225 | 223 | code.
|
226 |
| - <my-app></my-app> |
227 |
| - |
228 |
| - <script> |
229 |
| - // Rewrite the paths to load the files |
230 |
| - System.paths = { |
231 |
| - 'angular2/*':'/quickstart/angular2/*.js', // Angular |
232 |
| - 'rtts_assert/*': '/quickstart/rtts_assert/*.js', // Runtime assertions |
233 |
| - 'app': 'app.es6' // The my-app component |
234 |
| - }; |
235 |
| - |
236 |
| - // Kick off the application |
237 |
| - System.import('app'); |
238 |
| - </script> |
| 224 | + <head> |
| 225 | + <script src="https://jspm.io/system@0.16.js"></script> |
| 226 | + </head> |
239 | 227 |
|
240 | 228 | p.
|
241 |
| - The <code>System.paths</code> property above specifies |
242 |
| - the paths to the following modules: |
243 |
| - ul |
244 |
| - li The Angular framework |
245 |
| - li Optional assertions for runtime type checking |
246 |
| - li The component to display on the page |
| 229 | + Add the following module-loading code before the <code><my-app></code> tag: |
| 230 | + |
| 231 | + pre.prettyprint.linenums |
| 232 | + code. |
| 233 | + <script>System.import('app');</script> |
| 234 | + <my-app></my-app> |
247 | 235 |
|
248 | 236 |
|
249 | 237 | // STEP 8 - Run a local server ##########################
|
|
0 commit comments