@@ -26,34 +26,27 @@ include ../../../../_includes/_util-fns
26
26
:markdown
27
27
## Prerequisites
28
28
29
- We'll need a base of tools for all of our application development. We'll only install these once starting with
30
- [**node** and **npm**](https://docs.npmjs.com/getting-started/installing-node "Installing Node.js and updating npm").
29
+ We'll need a base of tools for our application development throughout this guide:
31
30
32
- Now use npm in a terminal (or Windows/Linux command line) to install the **TypeScript compiler** globally
31
+ - the **TypeScript compiler**
33
32
34
- pre.prettyprint.lang-bash
35
- code npm install -g typescript
36
-
37
- :markdown
38
- Use npm again to install the [**tsd package manager**](https://www.npmjs.com/package/tsd "TSD Package Manager")
39
- so we can download TypeScript type definitions files ("`.d.ts`" files)
40
- from the [DefinitelyTyped](http://definitelytyped.org/) repository.
33
+ - the [**tsd package manager**](https://www.npmjs.com/package/tsd "TSD Package Manager") so we can access
34
+ [TypeScript type definition files](http://definitelytyped.org/ "Definitely Typed") ("`.d.ts`" files).
41
35
42
- pre.prettyprint.lang-bash
43
- code npm install -g tsd
36
+ - **live-server**, a *static server* that runs our app in the browser and reloads the browser when any of the files change.
44
37
45
- :markdown
46
- Install a node **static server** to serve our application.
47
- We'll use **live-server** for this example because it performs a live reload by default and it's
48
- fun to watch the browser update as we make changes.
38
+ **Open** a terminal (or Windows/Linux command line) and issue the following `npm` command to install them all:
49
39
50
40
pre.prettyprint.lang-bash
51
- code npm install -g live-server
41
+ code npm install -g typescript tsd live-server
52
42
53
43
.l-sub-section
54
44
:markdown
55
- Our success depends upon installing compatible versions of these tools.
56
- Confirm your version numbers in a terminal window with these commands:
45
+ We depend upon [**node** and **npm**](https://docs.npmjs.com/getting-started/installing-node "Installing Node.js and updating npm")
46
+ to install packages such as these global tools.
47
+
48
+ We must be sure that we're installing Angular-compatible versions of these packages.
49
+ Issue the following commands in that same terminal window to confirm that we have the appropriate versions:
57
50
table
58
51
tr
59
52
th Command
@@ -118,26 +111,21 @@ include ../../../../_includes/_util-fns
118
111
:markdown
119
112
## Install npm packages
120
113
121
- Our application will need some 3rd party JavaScript files :
114
+ We need to install two JavaScript library packages :
122
115
123
116
>***angular.js***, the Angular 2 library.
124
117
125
- >***system.js***, a third-party open-source library that adds module loading functionality to our browser.
126
-
127
- >***traceur-runtime.js*** to transpile the TypeScript-generated JavaScript into the version of Javascript
128
- our browser understands (the version known as "ES5").
118
+ >***system.js***, an open-source library that provides module loading.
129
119
130
120
We'll install these package with `npm` and create an npm **`package.json`** configuration file
131
- that to maintain future packages as our application evolves.
121
+ to maintain them as our application evolves.
132
122
133
123
In a terminal window, go to the **root** folder and type:
134
124
```
135
125
npm init -y
136
-
126
+
137
127
```
138
128
139
- `npm` produced a `node_modules` folder that holds these packages and other packages that *they* require.
140
-
141
129
The essence of our `package.json` should look like this:
142
130
+ makeJson('gettingstarted/ts/package.json' , { paths: ' name, version, dependencies ' })
143
131
@@ -150,7 +138,6 @@ include ../../../../_includes/_util-fns
150
138
We prefer writing TypeScript apps in editors that understand TypeScript,
151
139
such as [Visual Studio Code](https://code.visualstudio.com/) and
152
140
[Web Storm](https://www.jetbrains.com/webstorm/features/).
153
-
154
141
Such editors improve the development experience by checking type information and
155
142
displaying API documentation ("intellisense") based on TypeScript definition files (`.d.ts`).
156
143
@@ -174,16 +161,15 @@ include ../../../../_includes/_util-fns
174
161
175
162
### Add the TypeScript configuration file
176
163
177
- We need to tell that editor how to interpret our TypeScript
178
- which we do with a configuration file named **`tsconfig.json`**.
179
- This configuration file also simplifies the TypeScript compilation command
180
- that we'll run very soon.
164
+ We'll add a configuration file named **`tsconfig.json`**
165
+ to tell the editor how to interpret our TypeScript code and
166
+ to simplify the TypeScript compilation command that we'll run very soon.
181
167
182
168
**Change to the `src` folder and create a `tsconfig.json`** file with the following content:
183
169
+ makeJson('gettingstarted/ts/src/tsconfig.json' , null , 'tsconfig.json' )
184
170
185
171
:markdown
186
- Our project should now look like this:
172
+ Our project folder structure should now look like this:
187
173
```
188
174
angular2-getting-started
189
175
├── node_modules
@@ -199,24 +185,20 @@ include ../../../../_includes/_util-fns
199
185
:markdown
200
186
## Create an `index.html`
201
187
202
- While in the **`src`** directory and
203
- add a new `index.html` file with the following HTML
188
+ While in the **`src`** directory we
189
+ add a new `index.html` file with the following content
204
190
205
- + makeExample('gettingstarted/ts/src/index.html' , null , 'index.html' ,
206
- {pnk: [/ (angular2\. dev\. js)/ , / (system\. src\. js)/ , / (traceur-runtime\. js)/ ]})
191
+ + makeExample('gettingstarted/ts/src/index.html' , null , 'index.html' )
207
192
208
193
.l-sub-section
209
194
:markdown
210
- Notice in the `<head>` element that we're loading the scripts we installed earlier with npm.
211
-
212
- There's an element called `<my-app>` in the `<body>`. This is a placeholder for the *root* of our
213
- application. Angular will display our application content here.
195
+ We're loading the library scripts in the `<head>` element from the `node_modules`
196
+ that we installed earlier with npm.
214
197
215
- The final inline script first configures the **`system.js`** module loader and then tells it
216
- to import the JavaScript file named `app` in the `app/` folder.
198
+ In the `<body>` is the app root element called `<my-app>` where Angular displays our application content.
217
199
218
- Subsequent module imports are triggered by a cascade of `import` statements
219
- beginning within `app.ts` itself .
200
+ The final inline script configures the **`system.js`** module loader and tells it
201
+ to import the *application file* named `app` from within the *folder* named `app/` .
220
202
221
203
**`app.ts`** is our main application file. We haven't written it yet. Let's do so now.
222
204
@@ -277,6 +259,8 @@ include ../../../../_includes/_util-fns
277
259
:markdown
278
260
## Confirm the final project and file structure
279
261
262
+ It should look like this
263
+
280
264
```
281
265
angular2-getting-started
282
266
├── node_modules
@@ -289,11 +273,6 @@ include ../../../../_includes/_util-fns
289
273
│ ├── tsconfig.json
290
274
└── package.json
291
275
```
292
- Seems like overkill for such a trivial application.
293
-
294
- We have ambitions. We aren't learning Angular to build "Hello, World". We intend
295
- to build great apps and we anticipate adding meat to these bones
296
- in the "Tour of Heroes" tutorial coming up very soon.
297
276
298
277
.l-main-section
299
278
:markdown
@@ -331,7 +310,7 @@ include ../../../../_includes/_util-fns
331
310
application message:
332
311
333
312
figure.image-display
334
- img( src ='/resources/images/examples/setup-example1 .png' alt ="Example of Todo App " )
313
+ img( src ='/resources/images/devguide/getting-started/my-first-app .png' alt ="Output of getting started app " )
335
314
336
315
:markdown
337
316
### Make some changes
@@ -342,27 +321,35 @@ include ../../../../_includes/_util-fns
342
321
The TypeScript compiler running in the first terminal window is watching our source code. It recompiles and produces
343
322
the revised *app.js*. The *live-server* sees that change and reloads the browser.
344
323
345
- Pretty nice!
346
-
347
324
.l-main-section
348
325
:markdown
349
- ## It's all a tree
326
+ ## Why so complicated?
327
+ To display a single line of text we
328
+
329
+ * installed a bunch of unfamiliar tools
330
+ * loaded a couple of libraries
331
+ * wrote configuration files for both `npm` and TypeScript
332
+ * configured something called `system.js` in our `index.html` and
333
+ told it to import our main file
334
+ * are compiling TypeScript in one terminal window and running the server in another
335
+
336
+ Perhaps we were expecting something simpler: an Angular library,
337
+ our application script, and a little HTML. This is all a bit much for a "Hello, World" app.
350
338
351
- We can think of Angular apps as a tree of components.
339
+ ** We have greater ambitions.**
352
340
353
- The `AppComponent` that we've been talking about acts as the top
354
- level container - the root of the tree - for the rest of our application .
355
- There's nothing special about the `AppComponent` name and we can use whatever makes sense to us.
341
+ We won't ask Angular to build "Hello, World".
342
+ We are asking it to help us build sophisticated applications with sophisticated requirements .
343
+ We're making strategic technology investments to reach our goals
356
344
357
- We've pinned the root component to an element in the `index.html` file where our application will
358
- render its view. The element is called `<my-app>` but there is nothing special about this
359
- name either.
345
+ * writing the app in TypeScript for team
346
+ productivity and maintainability.
360
347
361
- The *root component* loads the initial template for the application.
362
- That template could load other components such as menu bars, views, and forms
363
- that display information and respond to user gestures.
348
+ * designing with modules that we can load features dynamically
349
+ using the latest JavaScript `import` and `export` verbs.
364
350
365
- And these components could load yet more components until the browser page became a deep tree
366
- of nested functionality.
351
+ * running compiler and live-server commands that give us immediate feedback as we make changes.
367
352
368
- We'll walk through examples of these scenarios in the following pages.
353
+ The good news is that the overhead of setup is (mostly) behind us.
354
+ We're about to build a small application that demonstrates the great things
355
+ we can build with Angular 2. Join us on the [Tour of Heroes].
0 commit comments