Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 5f73911

Browse files
Foxandxsswardbell
authored andcommitted
chore(toh): change inputs array for input decorator/hero now a class
1 parent 10877bd commit 5f73911

File tree

22 files changed

+57
-77
lines changed

22 files changed

+57
-77
lines changed

public/docs/_examples/cb-component-communication/ts/app/hero.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export interface Hero {
1+
export class Hero {
22
name: string;
33
}
44

public/docs/_examples/toh-1/ts/app/app.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// #docregion pt1
22
import {Component} from 'angular2/core';
33

4-
// #docregion hero-interface-1
5-
interface Hero {
4+
// #docregion hero-class-1
5+
export class Hero {
66
id: number;
77
name: string;
88
}
9-
// #enddocregion hero-interface-1
9+
// #enddocregion hero-class-1
1010

1111
@Component({
1212
selector: 'my-app',

public/docs/_examples/toh-2/ts/app/app.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// #docregion pt2
22
import {Component} from 'angular2/core';
33

4-
interface Hero {
4+
export class Hero {
55
id: number;
66
name: string;
77
}
@@ -37,7 +37,7 @@ interface Hero {
3737
margin: 0 0 2em 0;
3838
list-style-type: none;
3939
padding: 0;
40-
width: 10em;
40+
width: 15em;
4141
}
4242
.heroes li {
4343
cursor: pointer;

public/docs/_examples/toh-3/ts/app/app.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {HeroDetailComponent} from './hero-detail.component';
3232
margin: 0 0 2em 0;
3333
list-style-type: none;
3434
padding: 0;
35-
width: 10em;
35+
width: 15em;
3636
}
3737
.heroes li {
3838
cursor: pointer;
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// #docplaster
22
// #docregion
33
// #docregion v1
4-
import {Component} from 'angular2/core';
4+
import {Component, Input} from 'angular2/core';
5+
56
// #enddocregion v1
67
// #docregion hero-import
78
import {Hero} from './hero';
@@ -10,7 +11,7 @@ import {Hero} from './hero';
1011
// #docregion v1
1112
@Component({
1213
selector: 'my-hero-detail',
13-
// #enddocregion v1
14+
// #enddocregion v1
1415
// #docregion template
1516
template: `
1617
<div *ngIf="hero">
@@ -21,18 +22,18 @@ import {Hero} from './hero';
2122
<input [(ngModel)]="hero.name" placeholder="name"/>
2223
</div>
2324
</div>
24-
`,
25+
`
2526
// #enddocregion template
26-
// #docregion inputs
27-
inputs: ['hero']
28-
// #enddocregion inputs
29-
// #docregion v1
27+
// #docregion v1
3028
})
3129
export class HeroDetailComponent {
3230
// #enddocregion v1
33-
// #docregion hero
31+
// #docregion hero-input
32+
@Input()
33+
// #docregion hero
3434
hero: Hero;
35-
// #enddocregion hero
35+
// #enddocregion hero
36+
// #enddocregion hero-input
3637
// #docregion v1
3738
}
3839
// #enddocregion v1

public/docs/_examples/toh-3/ts/app/hero.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// #docregion
2-
export interface Hero {
2+
export class Hero {
33
id: number;
44
name: string;
55
}

public/docs/_examples/toh-4/ts/app/app.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {HeroService} from './hero.service';
3232
margin: 0 0 2em 0;
3333
list-style-type: none;
3434
padding: 0;
35-
width: 10em;
35+
width: 15em;
3636
}
3737
.heroes li {
3838
cursor: pointer;

public/docs/_examples/toh-4/ts/app/hero-detail.component.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// #docregion
2-
import {Component} from 'angular2/core';
2+
import {Component, Input} from 'angular2/core';
33
import {Hero} from './hero';
44

55
@Component({
@@ -15,9 +15,8 @@ import {Hero} from './hero';
1515
<input [(ngModel)]="hero.name" placeholder="name"/>
1616
</div>
1717
</div>
18-
`,
19-
inputs: ['hero']
18+
`
2019
})
2120
export class HeroDetailComponent {
22-
hero: Hero;
21+
@Input() hero: Hero;
2322
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export interface Hero {
1+
export class Hero {
22
id: number;
33
name: string;
44
}

public/docs/_examples/toh-5/ts/app/hero-detail.component.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// #docregion
33
// #docregion v2
44
// #docregion import-oninit
5-
import { Component, OnInit } from 'angular2/core';
5+
import { Component, Input, OnInit } from 'angular2/core';
66
// #enddocregion import-oninit
77
// #docregion import-route-params
8-
import {RouteParams} from 'angular2/router';
8+
import { RouteParams } from 'angular2/router';
99
// #enddocregion import-route-params
1010

1111
import { Hero } from './hero';
@@ -20,15 +20,14 @@ import { HeroService } from './hero.service';
2020
templateUrl: 'app/hero-detail.component.html',
2121
// #enddocregion template-url
2222
// #enddocregion v2
23-
styleUrls: ['app/hero-detail.component.css'],
24-
inputs: ['hero']
23+
styleUrls: ['app/hero-detail.component.css']
2524
// #docregion v2
2625
})
2726
// #enddocregion extract-template
2827
// #docregion implement
2928
export class HeroDetailComponent implements OnInit {
3029
// #enddocregion implement
31-
hero: Hero;
30+
@Input() hero: Hero;
3231

3332
// #docregion ctor
3433
constructor(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export interface Hero {
1+
export class Hero {
22
id: number;
33
name: string;
44
}

public/docs/_examples/toh-5/ts/app/heroes.component.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
margin: 0 0 2em 0;
77
list-style-type: none;
88
padding: 0;
9-
width: 10em;
9+
width: 15em;
1010
}
1111
.heroes li {
1212
cursor: pointer;

public/docs/_examples/tutorial/ts/app/app.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ import {HeroService} from './hero.service';
2626
{path: '/detail/:id', name: 'HeroDetail', component: HeroDetailComponent}
2727
])
2828
export class AppComponent {
29-
public title = 'Tour of Heroes';
29+
title = 'Tour of Heroes';
3030
}

public/docs/_examples/tutorial/ts/app/dashboard.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {HeroService} from './hero.service';
99
styleUrls: ['app/dashboard.component.css']
1010
})
1111
export class DashboardComponent implements OnInit {
12-
public heroes: Hero[] = [];
12+
heroes: Hero[] = [];
1313

1414
constructor(private _heroService: HeroService, private _router: Router) { }
1515

public/docs/_examples/tutorial/ts/app/hero-detail.component.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, OnInit} from 'angular2/core';
1+
import {Component, Input, OnInit} from 'angular2/core';
22
import {RouteParams} from 'angular2/router';
33

44
import {Hero} from './hero';
@@ -7,11 +7,10 @@ import {HeroService} from './hero.service';
77
@Component({
88
selector: 'my-hero-detail',
99
templateUrl: 'app/hero-detail.component.html',
10-
styleUrls: ['app/hero-detail.component.css'],
11-
inputs: ['hero']
10+
styleUrls: ['app/hero-detail.component.css']
1211
})
1312
export class HeroDetailComponent implements OnInit {
14-
public hero: Hero;
13+
@Input() hero: Hero;
1514

1615
constructor(private _heroService: HeroService,
1716
private _routeParams: RouteParams) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export interface Hero {
1+
export class Hero {
22
id: number;
33
name: string;
44
}

public/docs/_examples/tutorial/ts/app/heroes.component.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
margin: 0 0 2em 0;
77
list-style-type: none;
88
padding: 0;
9-
width: 10em;
9+
width: 15em;
1010
}
1111
.heroes li {
1212
cursor: pointer;

public/docs/_examples/tutorial/ts/app/heroes.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import {Hero} from './hero';
1111
directives: [HeroDetailComponent]
1212
})
1313
export class HeroesComponent implements OnInit {
14-
public heroes: Hero[];
15-
public selectedHero: Hero;
14+
heroes: Hero[];
15+
selectedHero: Hero;
1616

1717
constructor(private _heroService: HeroService, private _router: Router) { }
1818

public/docs/ts/latest/tutorial/toh-pt1.jade

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,31 +66,15 @@ code-example(format="" language="bash").
6666
### Hero object
6767

6868
At the moment, our hero is just a name. Our hero needs more properties.
69-
Let's convert the `hero` from a literal string to an interface.
69+
Let's convert the `hero` from a literal string to a class.
7070

71-
Create a `Hero` interface with `id` and `name` properties.
71+
Create a `Hero` class with `id` and `name` properties.
7272
For now put this near the top of the `app.component.ts` file, just below the import statement.
7373

74-
+makeExample('toh-1/ts/app/app.component.ts', 'hero-interface-1', 'app.component.ts (Hero interface)')(format=".")
75-
76-
.l-sub-section
77-
:marked
78-
#### Interface or Class?
79-
Why a `Hero` interface and not a `Hero` class?
80-
We want a strongly typed `Hero`. We get strong typing with either option.
81-
Our choice depends on how we intend to use the `Hero`.
82-
83-
If we need a `Hero` that goes beyond simple properties, a `Hero` with logic and behavior,
84-
we must define a class.
85-
If we only need type checking, the interface is sufficient and lighter weight.
86-
87-
Lighter weight? Transpiling a class to JavaScript produces code.
88-
Transpiling an interface produces &mdash; nothing.
89-
If the class does nothing (and there is nothing for a `Hero` class to do right now),
90-
we prefer an interface.
74+
+makeExample('toh-1/ts/app/app.component.ts', 'hero-class-1', 'app.component.ts (Hero class)')(format=".")
9175

9276
:marked
93-
Now that we have a `Hero` interface, let’s refactor our component’s `hero` property to be of type `Hero`.
77+
Now that we have a `Hero` class, let’s refactor our component’s `hero` property to be of type `Hero`.
9478
Then initialize it with an id of `1` and the name, "Windstorm".
9579

9680
+makeExample('toh-1/ts-snippets/app.component.snippets.pt1.ts', 'hero-property-1', 'app.component.ts (Hero property)')(format=".")

public/docs/ts/latest/tutorial/toh-pt2.jade

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ code-example(format="." language="bash").
5151
+makeExample('toh-2/ts/app/app.component.ts', 'hero-array', 'app.component.ts (Hero array)')
5252

5353
:marked
54-
The `HEROES` array is of type `Hero`, the interface defined in part one,
54+
The `HEROES` array is of type `Hero`, the class defined in part one,
5555
to create an array of heroes.
5656
We aspire to fetch this list of heroes from a web service, but let’s take small steps
5757
first and display mock heroes.
5858

5959
### Exposing heroes
60-
Let’s create a public property in `AppComponent` that exposes the heroes for binding.
60+
Let’s create a property in `AppComponent` that exposes the heroes for binding.
6161

6262
+makeExample('toh-2/ts-snippets/app.component.snippets.pt2.ts', 'hero-array-1', 'app.component.ts (Hero array property)')
6363

public/docs/ts/latest/tutorial/toh-pt3.jade

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,13 @@ code-example(format="." language="bash").
7373
:marked
7474
-->
7575
:marked
76-
We begin by importing the `Component` function from Angular so that we have it handy when we create
77-
the metadata for our component.
78-
76+
We begin by importing the `Component` and `Input` decorators from Angular because we're going to need them soon.
77+
7978
We create metadata with the `@Component` decorator where we
8079
specify the selector name that identifies this component's element.
8180
Then we export the class to make it available to other components.
8281

83-
When we finish here, we'll import it into `AppComponent` and refer to its `<my-hero-detail>` element.
82+
When we finish here, we'll import it into `AppComponent` and create a corresponding `<my-hero-detail>` element.
8483
:marked
8584
#### Hero Detail Template
8685
At the moment, the *Heroes* and *Hero Detail* views are combined in one template in `AppComponent`.
@@ -100,18 +99,18 @@ code-example(format="." language="bash").
10099
Let’s add that `hero` property we were talking about to the component class.
101100
+makeExample('toh-3/ts/app/hero-detail.component.ts', 'hero')
102101
:marked
103-
Uh oh. We declared the `hero` property as type `Hero` but our `Hero` interface is over in the `app.component.ts` file.
104-
We have two components, each in their own file, that need to reference the `Hero` interface.
102+
Uh oh. We declared the `hero` property as type `Hero` but our `Hero` class is over in the `app.component.ts` file.
103+
We have two components, each in their own file, that need to reference the `Hero` class.
105104

106-
We solve the problem by relocating the `Hero` interface from `app.component.ts` to its own `hero.ts` file.
105+
We solve the problem by relocating the `Hero` class from `app.component.ts` to its own `hero.ts` file.
107106

108-
+makeExample('toh-3/ts/app/hero.ts', null, 'hero.ts (Exported Hero interface)')(format=".")
107+
+makeExample('toh-3/ts/app/hero.ts', null, 'hero.ts (Exported Hero class)')(format=".")
109108

110109
:marked
111-
We export the `Hero` interface from `hero.ts` because we'll need to reference it in both component files.
110+
We export the `Hero` class from `hero.ts` because we'll need to reference it in both component files.
112111
Add the following import statement near the top of both `app.component.ts` and `hero-detail.component.ts`.
113112

114-
+makeExample('toh-3/ts/app/hero-detail.component.ts', 'hero-import', 'hero-detail.component.ts and app.component.ts (Import the Hero interface)')
113+
+makeExample('toh-3/ts/app/hero-detail.component.ts', 'hero-import', 'hero-detail.component.ts and app.component.ts (Import the Hero class)')
115114

116115
:marked
117116
#### The *hero* property is an ***input***
@@ -137,14 +136,13 @@ code-example(format=".").
137136
*source* properties do not.
138137
:marked
139138
There are a couple of ways we can declare that `hero` is an *input*.
140-
We'll do it by adding an `inputs` array to the `@Component` metadata.
141-
+makeExample('toh-3/ts/app/hero-detail.component.ts', 'inputs')
139+
We'll do it the way we *prefer*, by annotating the `hero` property with the `@Input` decorator that we imported earlier.
140+
+makeExample('toh-3/ts/app/hero-detail.component.ts', 'hero-input')(format='.')
142141

143142
.l-sub-section
144143
:marked
145-
Learn about the `@Input()` decorator way in the
144+
Learn more about the `@Input()` decorator in the
146145
[Attribute Directives](../guide/attribute-directives.html#input) chapter.
147-
:marked
148146

149147
.l-main-section
150148
:marked

public/docs/ts/latest/tutorial/toh-pt4.jade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ code-example(format="." language="bash").
113113
We'll move the mock data to its own file.
114114

115115
Cut the `HEROES` array from `app.component.ts` and paste it to a new file in the `app` folder named `mock-heroes.ts`.
116-
We copy the `import {Hero} ...` statement as well because the heroes array uses the `Hero` interface.
116+
We copy the `import {Hero} ...` statement as well because the heroes array uses the `Hero` class.
117117

118118
+makeExample('toh-4/ts/app/mock-heroes.ts', null, 'mock-heroes.ts (Heroes array)')
119119
:marked

0 commit comments

Comments
 (0)