|
297 | 297 | code-pane(language="javascript" name="TypeScript" format="linenums").
|
298 | 298 | //TypeScript
|
299 | 299 | import {Component, View, bootstrap, For, If} from 'angular2/angular2';
|
300 |
| - @Component({ |
301 |
| - selector: 'display' |
302 |
| - }) |
| 300 | + ... |
303 | 301 | @View({
|
304 |
| - template: ` |
| 302 | + <span class='otl'>template</span>: ` |
305 | 303 | <p>My name: {{ myName }}</p>
|
306 | 304 | <p>Friends:</p>
|
307 | 305 | <ul>
|
|
314 | 312 | directives: [For, If]
|
315 | 313 | })
|
316 | 314 | class DisplayComponent {
|
317 |
| - myName: string; |
318 |
| - names: Array<string> |
| 315 | + ... |
| 316 | + } |
| 317 | + |
| 318 | + class FriendsService { |
| 319 | + names: Array<string>; |
319 | 320 | constructor() {
|
320 |
| - this.myName = "Alice"; |
321 |
| - this.names = ["Aarav", "Martín", "Shannon", "Ariana", "Kai"]; |
| 321 | + <span class='otl'>this.names = ["Aarav", "Martín", "Shannon"];</span> |
322 | 322 | }
|
323 | 323 | }
|
324 | 324 | code-pane(language="javascript" name="ES5" format="linenums").
|
325 | 325 | //ES5
|
326 |
| - function DisplayComponent() { |
| 326 | + function DisplayComponent(friends) { |
327 | 327 | this.myName = "Alice";
|
328 |
| - this.names = ["Aarav", "Martín", "Shannon", "Ariana", "Kai"]; |
| 328 | + this.names = friends.names; |
329 | 329 | }
|
330 | 330 | DisplayComponent.annotations = [
|
331 |
| - new angular.ComponentAnnotation({ |
332 |
| - selector: "display" |
333 |
| - }), |
| 331 | + ... |
334 | 332 | new angular.ViewAnnotation({
|
335 |
| - template: |
| 333 | + <span class='otl'>template</span>: ' |
336 | 334 | '<p>My name: {{ myName }}</p>' +
|
337 | 335 | '<p>Friends:</p>' +
|
338 | 336 | '<ul>' +
|
339 | 337 | '<li *for="#name of names">' +
|
340 | 338 | '{{ name }}' +
|
341 | 339 | '</li>' +
|
342 | 340 | '</ul>' +
|
343 |
| - '<p *if="names.length > 3">You have many friends!</p>', |
| 341 | + '<p *if="names.length > 3">You have many friends!</p>'', |
344 | 342 | directives: [angular.For, angular.If]
|
345 | 343 | })
|
346 | 344 | ];
|
| 345 | + |
| 346 | + function FriendsService () { |
| 347 | + <span class='otl'>this.names = ["Aarav", "Martín", "Shannon"];</span> |
| 348 | + } |
0 commit comments