1
1
include _util-fns
2
-
2
+
3
3
:marked
4
4
Good tools make application development quicker and easier to maintain than
5
5
if you did everything by hand.
6
-
6
+
7
7
The [**Angular CLI**](https://cli.angular.io/) is a **_command line interface_** tool
8
- that can create a project, add files, and perform a variety of ongoing development tasks such
8
+ that can create a project, add files, and perform a variety of ongoing development tasks such
9
9
as testing, bundling, and deployment.
10
-
11
- The goal in this guide is to build and run a simple Angular
12
- application in TypeScript, using the Angular CLI
10
+
11
+ The goal in this guide is to build and run a simple Angular
12
+ application in TypeScript, using the Angular CLI
13
13
while adhering to the [Style Guide](./guide/style-guide.html) recommendations that
14
14
benefit _every_ Angular project.
15
-
15
+
16
16
By the end of the chapter, you'll have a basic understanding of development with the CLI
17
17
and a foundation for both these documentation samples and for real world applications.
18
18
19
19
You'll pursue these ends in the following high-level steps:
20
-
20
+
21
21
1. [Set up](#devenv) the development environment.
22
22
2. [Create](#create-proj) a new project and skeleton application.
23
23
3. [Serve](#serve) the application.
@@ -29,7 +29,7 @@ include _util-fns
29
29
h2#devenv Step 1. Set up the Development Environment
30
30
:marked
31
31
You need to set up your development environment before you can do anything.
32
-
32
+
33
33
Install **[Node.js® and npm](https://nodejs.org/en/download/)**
34
34
if they are not already on your machine.
35
35
.l-sub-section
@@ -39,10 +39,10 @@ h2#devenv Step 1. Set up the Development Environment
39
39
Older versions produce errors, but newer versions are fine.
40
40
:marked
41
41
Then **install the [Angular CLI](https://github.com/angular/angular-cli)** globally.
42
-
42
+
43
43
code-example( language ="sh" class ="code-shell" ) .
44
44
npm install -g @angular/cli
45
-
45
+
46
46
.l-main-section
47
47
h2#create-project Step 2. Create a new project
48
48
:marked
@@ -56,7 +56,7 @@ code-example(language="sh" class="code-shell").
56
56
57
57
.l-sub-section
58
58
:marked
59
- Patience please.
59
+ Patience please.
60
60
It takes time to set up a new project, most of it spent installing npm packages.
61
61
62
62
.l-main-section
@@ -67,41 +67,41 @@ h2#serve Step 3: Serve the application
67
67
code-example( language ="sh" class ="code-shell" ) .
68
68
cd my-app
69
69
ng serve --open
70
-
70
+
71
71
:marked
72
- The `ng serve` command launches the server, watches your files,
72
+ The `ng serve` command launches the server, watches your files,
73
73
and rebuilds the app as you make changes to those files.
74
74
75
- Using the `--open` (or just `-o`) option will automatically open your browser
76
- on `http://localhost:4200/`.
77
-
75
+ Using the `--open` (or just `-o`) option will automatically open your browser
76
+ on `http://localhost:4200/`.
77
+
78
78
Your app greets you with a message:
79
-
79
+
80
80
figure.image-display
81
81
img( src ='/resources/images/devguide/cli-quickstart/app-works.png' alt ="The app works!" )
82
82
83
83
.l-main-section
84
84
h2#first-component Step 4: Edit your first Angular component
85
85
:marked
86
- The CLI created the first Angular component for you.
86
+ The CLI created the first Angular component for you.
87
87
This is the _root component_ and it is named `app-root`.
88
88
You can find it in `./src/app/app.component.ts`.
89
89
90
90
:marked
91
91
Open the component file and change the `title` property from _app works!_ to _My First Angular App_:
92
-
92
+
93
93
+ makeExample('cli-quickstart/ts/src/app/app.component.ts' , 'title' , 'src/app/app.component.ts' )( format ="." )
94
94
95
95
:marked
96
96
The browser reloads automatically with the revised title. That's nice, but it could look better.
97
-
98
- Open `src/app/cli-quickstart .component.css` and give the component some style.
97
+
98
+ Open `src/app/app .component.css` and give the component some style.
99
99
100
100
+ makeExample('cli-quickstart/ts/src/app/app.component.css' , null , 'src/app/app.component.css' )( format ="." )
101
101
102
102
figure.image-display
103
- img( src ='/resources/images/devguide/cli-quickstart/my-first-app.png' alt ="Output of QuickStart app" )
104
-
103
+ img( src ='/resources/images/devguide/cli-quickstart/my-first-app.png' alt ="Output of QuickStart app" )
104
+
105
105
:marked
106
106
Looking good!
107
107
@@ -123,11 +123,11 @@ figure.image-display
123
123
124
124
The first file you should check out is `README.md`.
125
125
It has some basic information on how to use CLI commands.
126
- Whenever you want to know more about how Angular CLI works make sure to visit
127
- [the Angular CLI repository](https://github.com/angular/angular-cli) and
126
+ Whenever you want to know more about how Angular CLI works make sure to visit
127
+ [the Angular CLI repository](https://github.com/angular/angular-cli) and
128
128
[Wiki](https://github.com/angular/angular-cli/wiki).
129
129
130
- Some of the generated files might be unfamiliar to you.
130
+ Some of the generated files might be unfamiliar to you.
131
131
132
132
block src-files
133
133
:marked
@@ -175,7 +175,7 @@ table(width="100%")
175
175
:marked
176
176
Defines the `AppComponent` along with an HTML template, CSS stylesheet, and a unit test.
177
177
It is the **root** component of what will become a tree of nested components
178
- as the application evolves.
178
+ as the application evolves.
179
179
tr
180
180
td <code >app/app.module.ts</code >
181
181
td
@@ -187,16 +187,16 @@ table(width="100%")
187
187
td <code >assets/*</code >
188
188
td
189
189
:marked
190
- A folder where you can put images and anything else to be copied wholesale
191
- when you build your application.
190
+ A folder where you can put images and anything else to be copied wholesale
191
+ when you build your application.
192
192
tr
193
193
td <code >environments/*</code >
194
194
td
195
195
:marked
196
196
This folder contains one file for each of your destination environments,
197
197
each exporting simple configuration variables to use in your application.
198
198
The files are replaced on-the-fly when you build your app.
199
- You might use a different API endpoint for development than you do for production
199
+ You might use a different API endpoint for development than you do for production
200
200
or maybe different analytics tokens.
201
201
You might even use some mock services.
202
202
Either way, the CLI has you covered.
@@ -212,7 +212,7 @@ table(width="100%")
212
212
:marked
213
213
The main HTML page that is served when someone visits your site.
214
214
Most of the time you'll never need to edit it.
215
- The CLI automatically adds all `js` and `css` files when building your app so you
215
+ The CLI automatically adds all `js` and `css` files when building your app so you
216
216
never need to add any `<script>` or `<link>` tags here manually.
217
217
tr
218
218
td <code >main.ts</code >
@@ -235,7 +235,7 @@ table(width="100%")
235
235
td <code >styles.css</code >
236
236
td
237
237
:marked
238
- Your global styles go here.
238
+ Your global styles go here.
239
239
Most of the time you'll want to have local styles in your components for easier maintenance,
240
240
but styles that affect all of your app need to be in a central place.
241
241
tr
@@ -249,15 +249,15 @@ table(width="100%")
249
249
td <code >tsconfig.{app|spec}.json</code >
250
250
td
251
251
:marked
252
- TypeScript compiler configuration for the Angular app (`tsconfig.app.json`)
252
+ TypeScript compiler configuration for the Angular app (`tsconfig.app.json`)
253
253
and for the unit tests (`tsconfig.spec.json`).
254
254
255
255
256
256
block root-files
257
257
:marked
258
258
### The root folder
259
- The `src/` folder is just one of the items inside the project's root folder.
260
- Other files help you build, test, maintain, document, and deploy the app.
259
+ The `src/` folder is just one of the items inside the project's root folder.
260
+ Other files help you build, test, maintain, document, and deploy the app.
261
261
These files go in the root folder next to `src/`.
262
262
263
263
.filetree
@@ -277,8 +277,8 @@ block root-files
277
277
.file package.json
278
278
.file protractor.conf.js
279
279
.file README.md
280
- .file tsconfig.json
281
- .file tslint.json
280
+ .file tsconfig.json
281
+ .file tslint.json
282
282
283
283
style td, th {vertical-align: top}
284
284
table( width ="100%" )
@@ -291,15 +291,15 @@ table(width="100%")
291
291
td <code >e2e/</code >
292
292
td
293
293
:marked
294
- Inside `e2e/` live the End-to-End tests.
294
+ Inside `e2e/` live the End-to-End tests.
295
295
They shouldn't be inside `src/` because e2e tests are really a separate app that
296
- just so happens to test your main app.
296
+ just so happens to test your main app.
297
297
That's also why they have their own `tsconfig.e2e.json`.
298
298
tr
299
299
td <code >node_modules/</code >
300
300
td
301
301
:marked
302
- `Node.js` creates this folder and puts all third party modules listed in
302
+ `Node.js` creates this folder and puts all third party modules listed in
303
303
`package.json` inside of it.
304
304
tr
305
305
td <code >.angular-cli.json</code >
@@ -359,11 +359,11 @@ table(width="100%")
359
359
Linting configuration for [TSLint](https://palantir.github.io/tslint/) together with
360
360
[Codelyzer](http://codelyzer.com/), used when running `ng lint`.
361
361
Linting helps keep your code style consistent.
362
-
362
+
363
363
.l-sub-section
364
364
:marked
365
365
### Next Step
366
366
367
- If you're new to Angular, continue on the
368
- [learning path](guide/learning-angular.html "Angular learning path").
367
+ If you're new to Angular, continue on the
368
+ [learning path](guide/learning-angular.html "Angular learning path").
369
369
You can skip the "Setup" step since you're already using the Angular CLI setup.
0 commit comments