7
7
8
8
9
9
p.
10
- These instructions assume that you already have the Dart SDK
10
+ These instructions assume that you already have the
11
+ <a href =" https://www.dartlang.org/downloads/" >Dart SDK</a >
11
12
and any tools you like to use with Dart.
12
- If not, go
13
- <a href =" https://www.dartlang.org/downloads/" >download Dart</a >.
14
- Then return here.
13
+ If you don't have a favorite editor already, try
14
+ <a href =" https://confluence.jetbrains.com/display/WI/Getting+started+with+Dart" >WebStorm</a >,
15
+ which comes with a Dart plugin.
16
+ You can also download
17
+ <a href =" https://www.dartlang.org/tools/" >Dart plugins for
18
+ other IDEs and editors</a >.
15
19
16
- // STEP 1 - Create a project ##########################
20
+ p.
21
+ Once you have the Dart SDK and any other tools you want, return here.
22
+
23
+ //- STEP 1 - Create a project ##########################
17
24
.l-main-section
18
25
h2#section-install-angular 1. Create a project
19
26
20
27
p.
21
28
Create a new directory, and put a file named
22
29
<code >pubspec.yaml</code > in it.
23
30
24
- pre.prettyprint
25
- code.
26
- > mkdir hello_world
27
- > cd hello_world
28
- > vim pubspec.yaml # Use your favorite editor!
31
+ code-example( language ="sh" ) .
32
+ > <span class =" blk" >mkdir hello_world</span >
33
+ > <span class =" blk" >cd hello_world</span >
34
+ > <span class =" blk" >vim pubspec.yaml</span > # Use your favorite editor!
29
35
30
36
p.
31
- In <code >pubspec.yaml</code >, add the angular2 and browser packages as dependencies.
32
- Angular 2 is changing rapidly, so specify an exact version:
33
- <b >2.0.0-alpha.23</b >.
34
-
35
- pre.prettyprint.linenums.lang-basic
36
- code.
37
- name: hello_world
38
- version: 0.0.1
39
- dependencies:
40
- angular2: 2.0.0-alpha.23
41
- browser: any
37
+ In <code >pubspec.yaml</code >,
38
+ specify the angular2 and browser packages as dependencies,
39
+ as well as the angular2 transformer.
40
+ Angular 2 is changing rapidly, so provide an exact version:
41
+ <b >2.0.0-alpha.25</b >.
42
+
43
+ code-example( language ="yaml" format ="linenums" ) .
44
+ name: hello_world
45
+ version: 0.0.1
46
+ dependencies:
47
+ angular2: 2.0.0-alpha.25
48
+ browser: ^0.10.0+2
49
+ transformers:
50
+ - angular2:
51
+ entry_points: web/main.dart
42
52
p.
43
53
In the same directory, run <code >pub get</code >
44
54
to install the angular2 and browser packages
45
55
(along with the packages they depend on):
46
56
47
- pre.prettyprint.lang-basic
48
- code.
49
- > pub get
57
+ code-example( language ="sh" ) .
58
+ > <span class =" blk" >pub get</span >
50
59
51
- // PENDING: Create template? Link to pub/pubspec docs?
52
- // Is browser really needed?
60
+ //- PENDING: Create template? Link to pub/pubspec docs?
53
61
54
62
55
- // STEP 2 - Import Angular ##########################
63
+ //- STEP 2 - Import Angular ##########################
56
64
.l-main-section
57
65
h2#section-transpile 2. Import Angular
58
66
59
67
p.
60
68
Still in the same directory, create a <code >web</code > directory.
61
69
Create a file under <code >web</code > named <code >main.dart</code >.
62
70
63
- pre.prettyprint
64
- code.
65
- > mkdir web
66
- > vim web/main.dart # Use your favorite editor!
71
+ code-example( language ="sh" ) .
72
+ > <span class =" blk" >mkdir web</span >
73
+ > <span class =" blk" >vim web/main.dart</span > # Use your favorite editor!
67
74
68
75
p.
69
76
Edit <code >web/main.dart</code > to import the angular2 library
70
- and (for now) two reflection libraries:
71
-
72
- // pre.prettyprint.linenums
73
- pre.prettyprint
74
- code.
75
- import 'package:angular2/angular2.dart';
77
+ and two reflection libraries:
76
78
77
- // These imports will go away soon:
78
- import 'package:angular2/src/reflection/reflection.dart' show reflector;
79
- import 'package:angular2/src/reflection/reflection_capabilities.dart' show ReflectionCapabilities;
79
+ code-example( language ="dart" format ="linenums" ) .
80
+ import 'package:angular2/angular2.dart';
81
+ import 'package:angular2/src/reflection/reflection.dart' show reflector;
82
+ import 'package:angular2/src/reflection/reflection_capabilities.dart' show ReflectionCapabilities;
80
83
81
- // [PENDING: add line numbers once we can specify where they start]
82
-
83
- // STEP 3 - Define a component ##########################
84
+ //- STEP 3 - Define a component ##########################
84
85
.l-main-section
85
86
86
87
h2#section-angular-create-account 3. Define a component
89
90
Update <code >web/main.dart</code >, adding the following code
90
91
after the imports:
91
92
92
- pre.prettyprint
93
- code.
94
- @Component(
95
- selector: 'my-app'
96
- )
97
- @View(
98
- template: '< h1> Hello {{ name }}< /h1> '
99
- )
100
- class AppComponent {
101
- String name = 'Alice';
102
- }
103
-
104
- // [PENDING: add line numbers once we can specify where they start]
93
+ code-example( language ="dart" format ="linenums:5" ) .
94
+ @Component(
95
+ selector: 'my-app'
96
+ )
97
+ @View(
98
+ template: '< h1> Hello {{ name }}< /h1> '
99
+ )
100
+ class AppComponent {
101
+ String name = 'Alice';
102
+ }
105
103
106
104
p.
107
105
The code you just added creates a component that
125
123
specify a <code >templateUrl</code > property
126
124
and give it the path to the HTML file.
127
125
128
- pre.prettyprint
129
- code.
130
- @Component(
131
- selector: 'my-app'
132
- )
133
- @View(
134
- template: '< h1> Hello {{ name }}< /h1> '
135
- )
136
-
137
- // [PENDING: add line numbers once we can specify where they start]
126
+ code-example( language ="dart" ) .
127
+ @Component(
128
+ selector: 'my-app'
129
+ )
130
+ @View(
131
+ template: '< h1> Hello {{ name }}< /h1> '
132
+ )
138
133
139
134
p.
140
135
The annotations above specify an HTML tag of <code >< ; my-app> ; </code >
154
149
template renders, "Hello Alice" appears instead of
155
150
<span ng-non-bindable >"Hello {{ name }}"</span >.
156
151
157
- pre.prettyprint
158
- code.
159
- class AppComponent {
160
- String name = 'Alice';
161
- }
162
-
163
- // [PENDING: add line numbers once we can specify where they start]
164
-
152
+ code-example( language ="dart" ) .
153
+ class AppComponent {
154
+ String name = 'Alice';
155
+ }
165
156
166
- // STEP 4 - Bootstrap ##########################
157
+ //- STEP 4 - Bootstrap ##########################
167
158
.l-main-section
168
159
h2#section-transpile 4. Bootstrap
169
160
170
161
p.
171
162
Add the following code to the bottom of <code >web/main.dart</code >:
172
163
173
- pre.prettyprint
174
- code.
175
- main() {
176
- // Temporarily needed.
177
- reflector.reflectionCapabilities = new ReflectionCapabilities();
178
-
179
- bootstrap(AppComponent);
180
- }
181
-
182
- // [PENDING: add line numbers once we can specify where they start]
164
+ code-example( language ="dart" format ="linenums:15" ) .
165
+ main() {
166
+ reflector.reflectionCapabilities = new ReflectionCapabilities();
167
+ bootstrap(AppComponent);
168
+ }
183
169
184
170
p.
185
171
This code adds a <code >main()</code > function
188
174
you defined above.
189
175
190
176
p.
191
- Setting the value of
192
- <code >reflector.reflectionCapabilities</code >
193
- is a temporary workaround
194
- that you can remove once Angular's transformer is available.
195
-
196
-
197
- // STEP 5 - Declare the HTML ##########################
177
+ Setting the value of <code >reflector.reflectionCapabilities</code >
178
+ lets your app use the Dart VM's reflection (dart:mirrors)
179
+ when running in Dartium.
180
+ Reflection is fast in native Dart,
181
+ so using it makes sense during development.
182
+ Later, when you build a JavaScript version of your app,
183
+ the Angular transformer will
184
+ convert the reflection-using code to static code,
185
+ so your generated JavaScript can be smaller and faster.
186
+
187
+
188
+ //- STEP 5 - Declare the HTML ##########################
198
189
.l-main-section
199
190
200
191
h2#section-angular-create-account 5. Declare the HTML
@@ -204,53 +195,110 @@ p.
204
195
the following code,
205
196
which loads <code >main.dart</code > and instantiates the my-app component:
206
197
207
- pre.prettyprint.linenums
208
- code.
209
- < !doctype html>
210
- < html>
211
- < head>
212
- < title> Angular 2 Quickstart< /title>
213
- < /head>
214
- < body>
215
- < my-app> < /my-app>
216
-
217
- < script type="application/dart" src="main.dart"> < /script>
218
- < script src="packages/browser/dart.js"> < /script>
219
- < /body>
220
- < /html>
221
-
222
- // STEP 6 - Build and run ##########################
198
+ code-example( language ="html" format ="linenums" ) .
199
+ < !doctype html>
200
+ < html>
201
+ < head>
202
+ < title> Angular 2 Quickstart< /title>
203
+ < /head>
204
+ < body>
205
+ < my-app> < /my-app>
206
+
207
+ < script type="application/dart" src="main.dart"> < /script>
208
+ < script src="packages/browser/dart.js"> < /script>
209
+ < /body>
210
+ < /html>
211
+
212
+ //- STEP 6 - Run ##########################
223
213
.l-main-section
224
214
225
- h2#section-angular-run-app 6. Build and run your app
215
+ h2#section-angular-run-app 6. Run your app
226
216
227
217
p.
228
- You have several options for running your app.
229
- The quickest and easiest, for now,
230
- is to open your project in <b >Dart Editor</b >,
231
- right-click <b >web/index.html</b >,
232
- and choose <b >Open in Dartium</b >.
233
- This starts a web server
234
- and opens your app in an experimental browser that contains the Dart VM.
235
-
236
- // TODO: screenshot? embedded app?
218
+ You have a few options for running your app.
219
+ One is to launch a local HTTP server
220
+ and then view the app in
221
+ <a href =" https://www.dartlang.org/tools/dartium/" >Dartium</a >.
222
+ You can use whatever server you like, such as WebStorm's server
223
+ or Python's SimpleHTTPServer.
237
224
238
225
p.
239
226
Another option is to build and serve the app using <code >pub serve</code >,
240
- and then run it by visiting <b >http://localhost:8080</b > in a browser.
241
- Generating the JavaScript takes a few seconds when you first visit the page,
242
- and the generated JavaScript is currently large.
243
- The generated JavaScript will be smaller once
244
- Angular's transformer becomes available.
227
+ and then run it by visiting <b >http://localhost:8080</b > in any modern browser.
228
+ Pub serve generates the JavaScript on the fly,
229
+ which takes a few seconds when you first visit the page.
230
+
231
+ p.
232
+ Once the app is running,
233
+ you should see <b >Hello Alice</b > in your browser window.
245
234
246
- // [PENDING: Update when transformer is working!]
247
235
248
- // WHAT'S NEXT... ##########################
236
+ //- STEP 7 - Generate JavaScript ##########################
237
+ .l-main-section
238
+
239
+ h2#section-angular-run-app 7. Generate JavaScript
240
+
241
+ p.
242
+ Before you can deploy your app, you need to generate JavaScript files.
243
+ Compiling your Dart code to JavaScript is easy:
244
+ just run <code >pub build</code >.
245
+
246
+ code-example( language ="basic" ) .
247
+ > <span class =" blk" >pub build</span >
248
+ Loading source assets...
249
+ Loading angular2 transformers...
250
+ INFO: Formatter is being overwritten.
251
+ Building hello_world... (3.1s)
252
+ [Info from Dart2JS]:
253
+ Compiling hello_world|web/main.dart...
254
+ [Info from Dart2JS]:
255
+ Took 0:00:16.123086 to compile hello_world|web/main.dart.
256
+ Built 41 files to "build".
257
+ //- REGENERATE THIS OUTPUT - or delete it? - when updating from 2.0.0-alpha.25
258
+
259
+ p.
260
+ The generated JavaScript appears, along with supporting files,
261
+ under the <code >build</code > directory.
262
+
263
+ p.
264
+ When you generate JavaScript for an Angular app,
265
+ be sure you use the Angular transformer.
266
+ It analyzes your code,
267
+ converting reflection-using code to static code
268
+ that Dart's build tools can compile to faster, smaller JavaScript.
269
+ The highlighted lines in <code >pubspec.yaml</code >
270
+ configure the Angular transformer:
271
+
272
+ code-example( language ="yaml" format ="linenums" ) .
273
+ name: hello_world
274
+ version: 0.0.1
275
+ dependencies:
276
+ angular2: 2.0.0-alpha.25
277
+ browser: ^0.10.0+2
278
+ <span class =" pnk" >transformers:
279
+ - angular2:
280
+ entry_points: web/main.dart</span >
281
+ p.
282
+ The <code >entry_points</code > entry
283
+ identifies the Dart file in your app
284
+ that has a <code >main()</code > function.
285
+ For more information, see the
286
+ <a href =" https://github.com/angular/angular/wiki/Angular-2-Dart-Transformer" >Angular
287
+ transformer wiki page</a >.
288
+
289
+ //- WHAT'S NEXT... ##########################
249
290
.l-main-section
250
291
h2#section-transpile Great job! Next step...
251
292
252
293
p.
253
- We plan to add a developer guide soon.
254
- Until then, check out <a href =" resources.html" >Angular Resources</a >.
255
- To learn more about Dart, go to
256
- <a href =" https://www.dartlang.org" >dartlang.org</a >.
294
+ Follow the <a href =" guide" >developer guide</a >
295
+ to continue playing with Angular 2 for Dart.
296
+
297
+ p.
298
+ Or read more about Angular or Dart:
299
+
300
+ ul
301
+ li
302
+ <a href =" resources.html" >Angular resources</a >
303
+ li
304
+ <a href =" https://www.dartlang.org" >dartlang.org</a >
0 commit comments