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

Commit 0056a68

Browse files
committed
docs(style-guide): ./ prefix for template/style URLs and other improvements
1 parent 4ec1736 commit 0056a68

File tree

24 files changed

+183
-160
lines changed

24 files changed

+183
-160
lines changed

public/docs/_examples/style-guide/ts/03-06/app/heroes/shared/hero.service.avoid.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* avoid */
44

55
import { ExceptionService, SpinnerService, ToastService } from '../../core';
6-
import { Http, Response } from '@angular/http';
6+
import { Http } from '@angular/http';
77
import { Injectable } from '@angular/core';
88
import { Hero } from './hero.model';
99
// #enddocregion example
@@ -20,12 +20,12 @@ export class HeroService {
2020

2121
getHero(id: number) {
2222
return this.http.get(`api/heroes/${id}`)
23-
.map((res: Response) => res.json().data);
23+
.map(response => response.json().data as Hero);
2424
}
2525

2626
getHeroes() {
2727
return this.http.get(`api/heroes`)
28-
.map((res: Response) => res.json().data);
28+
.map(response => response.json().data as Hero[]);
2929
}
3030

3131
}

public/docs/_examples/style-guide/ts/03-06/app/heroes/shared/hero.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// #docregion
22
// #docregion example
33
import { Injectable } from '@angular/core';
4-
import { Http, Response } from '@angular/http';
4+
import { Http } from '@angular/http';
55

66
import { Hero } from './hero.model';
77
import { ExceptionService, SpinnerService, ToastService } from '../../core';
@@ -20,12 +20,12 @@ export class HeroService {
2020

2121
getHero(id: number) {
2222
return this.http.get(`api/heroes/${id}`)
23-
.map((res: Response) => res.json().data);
23+
.map(response => response.json().data as Hero);
2424
}
2525

2626
getHeroes() {
2727
return this.http.get(`api/heroes`)
28-
.map((res: Response) => res.json().data);
28+
.map(response => response.json().data as Hero[]);
2929
}
3030

3131
}

public/docs/_examples/style-guide/ts/04-08/app/app.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import { NgModule } from '@angular/core';
55
import { BrowserModule } from '@angular/platform-browser';
66
// #enddocregion example
7-
import { RouterModule } from '@angular/router';
7+
import { RouterModule } from '@angular/router';
88
// #docregion example
99

10-
import { AppComponent } from './app.component';
10+
import { AppComponent } from './app.component';
1111
import { HeroesComponent } from './heroes/heroes.component';
1212

1313
@NgModule({
Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
1-
// #docplaster
2-
// #docregion
3-
// #docregion example
41
import { Component, OnInit } from '@angular/core';
52

63
@Component({
7-
// #enddocregion example
84
moduleId: module.id,
9-
// #docregion example
105
selector: 'toh-heroes',
116
templateUrl: './heroes.component.html'
127
})
138
export class HeroesComponent implements OnInit {
14-
// #enddocregion example
15-
// #docregion example
16-
constructor() { }
9+
constructor() { /* ... */ }
1710

18-
ngOnInit() { }
11+
ngOnInit() { /* ... */ }
1912
}
20-
// #enddocregion example
21-
Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
1-
// #docplaster
21
// #docregion
3-
// #docregion example
4-
import { Component, OnInit } from '@angular/core';
2+
import { Component } from '@angular/core';
53

64
import { FilterTextService } from '../shared/filter-text/filter-text.service';
75

86
@Component({
9-
// #enddocregion example
107
moduleId: module.id,
11-
// #docregion example
128
selector: 'toh-heroes',
139
templateUrl: './heroes.component.html'
1410
})
15-
export class HeroesComponent implements OnInit {
16-
// #enddocregion example
17-
// #docregion example
18-
filteredHeroes: any[] = [];
19-
20-
constructor(private filterService: FilterTextService) { }
11+
export class HeroesComponent {
2112

2213
heroes = [
2314
{ id: 1, name: 'Windstorm' },
@@ -26,13 +17,12 @@ export class HeroesComponent implements OnInit {
2617
{ id: 4, name: 'Tornado' }
2718
];
2819

20+
filteredHeroes = this.heroes;
21+
22+
constructor(private filterService: FilterTextService) { }
23+
2924
filterChanged(searchText: string) {
3025
this.filteredHeroes = this.filterService.filter(searchText, ['id', 'name'], this.heroes);
3126
}
32-
33-
ngOnInit() {
34-
this.filteredHeroes = this.heroes;
35-
}
3627
}
37-
// #enddocregion example
3828

public/docs/_examples/style-guide/ts/04-11/app/heroes/heroes.component.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
1-
// #docplaster
2-
// #docregion
3-
// #docregion example
41
import { Component } from '@angular/core';
52

6-
import { LoggerService } from '../core/logger.service';
3+
import { LoggerService } from '../core/logger.service';
74
import { SpinnerService } from '../core/spinner/spinner.service';
85

96
@Component({
10-
// #enddocregion example
117
moduleId: module.id,
12-
// #docregion example
138
selector: 'toh-heroes',
149
templateUrl: './heroes.component.html'
1510
})
1611
export class HeroesComponent {
17-
// #enddocregion example
18-
// #docregion example
1912
heroes: any[];
2013

2114
constructor(
@@ -38,4 +31,3 @@ export class HeroesComponent {
3831
}, 2000);
3932
}
4033
}
41-
// #enddocregion example
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
// #docplaster
2-
// #docregion
3-
// #docregion example
41
import { Component } from '@angular/core';
52

63
import { LoggerService } from '../core/logger.service';
74

85
@Component({
9-
// #enddocregion example
106
moduleId: module.id,
11-
// #docregion example
127
selector: 'toh-heroes',
138
templateUrl: './heroes.component.html'
149
})
1510
export class HeroesComponent {
16-
// #enddocregion example
17-
// #docregion example
1811
heroes: any[];
1912

2013
constructor(private loggerService: LoggerService) { }
@@ -30,4 +23,3 @@ export class HeroesComponent {
3023
this.loggerService.log(`We have ${HeroesComponent.length} heroes`);
3124
}
3225
}
33-
// #enddocregion example

public/docs/_examples/style-guide/ts/05-02/app/heroes/shared/hero-button/hero-button.component.avoid.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
// #docplaster
2-
// #docregion
32
import { Component } from '@angular/core';
43
// #docregion example
54
/* avoid */
65

76
@Component({
8-
// #enddocregion example
97
moduleId: module.id,
10-
// #docregion example
118
selector: 'tohHeroButton',
129
templateUrl: './hero-button.component.html'
1310
})

public/docs/_examples/style-guide/ts/05-02/app/heroes/shared/hero-button/hero-button.component.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
// #docplaster
2-
// #docregion
31
import { Component } from '@angular/core';
42

53
// #docregion example
64
@Component({
7-
// #enddocregion example
85
moduleId: module.id,
9-
// #docregion example
106
selector: 'toh-hero-button',
117
templateUrl: './hero-button.component.html'
128
})

public/docs/_examples/style-guide/ts/05-03/app/heroes/shared/hero-button/hero-button.component.avoid.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
// #docplaster
2-
// #docregion
31
import { Component } from '@angular/core';
42
// #docregion example
53
/* avoid */
64

75
@Component({
8-
// #enddocregion example
96
moduleId: module.id,
10-
// #docregion example
117
selector: '[tohHeroButton]',
128
templateUrl: './hero-button.component.html'
139
})

public/docs/_examples/style-guide/ts/05-03/app/heroes/shared/hero-button/hero-button.component.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
// #docplaster
2-
// #docregion
31
import { Component } from '@angular/core';
42

53
// #docregion example
64
@Component({
7-
// #enddocregion example
85
moduleId: module.id,
9-
// #docregion example
106
selector: 'toh-hero-button',
117
templateUrl: './hero-button.component.html'
128
})
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { NgModule } from '@angular/core';
1+
import { NgModule } from '@angular/core';
22
import { BrowserModule } from '@angular/platform-browser';
3-
import { RouterModule } from '@angular/router';
3+
import { RouterModule } from '@angular/router';
44

5-
import { AppComponent } from './app.component';
5+
import { AppComponent } from './app.component';
66
import { HeroesComponent } from './heroes';
7+
import { HeroService } from './heroes/shared';
78

89
@NgModule({
910
imports: [
@@ -14,6 +15,7 @@ import { HeroesComponent } from './heroes';
1415
AppComponent,
1516
HeroesComponent
1617
],
17-
exports: [ AppComponent ]
18+
exports: [ AppComponent ],
19+
providers: [ HeroService ]
1820
})
1921
export class AppModule {}

public/docs/_examples/style-guide/ts/05-04/app/heroes/heroes.component.avoid.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// #docregion
21
import { Component, OnInit } from '@angular/core';
2+
import { Observable } from 'rxjs/Observable';
3+
4+
import { Hero, HeroService } from './shared';
35

4-
import { Hero } from './shared/hero.model';
56
// #docregion example
67
/* avoid */
78

@@ -11,7 +12,7 @@ import { Hero } from './shared/hero.model';
1112
<div>
1213
<h2>My Heroes</h2>
1314
<ul class="heroes">
14-
<li *ngFor="let hero of heroes">
15+
<li *ngFor="let hero of heroes | async" (click)="selectedHero=hero">
1516
<span class="badge">{{hero.id}}</span> {{hero.name}}
1617
</li>
1718
</ul>
@@ -51,9 +52,13 @@ import { Hero } from './shared/hero.model';
5152
`]
5253
})
5354
export class HeroesComponent implements OnInit {
54-
heroes: Hero[];
55+
heroes: Observable<Hero[]>;
5556
selectedHero: Hero;
5657

57-
ngOnInit() {}
58+
constructor(private heroService: HeroService) { }
59+
60+
ngOnInit() {
61+
this.heroes = this.heroService.getHeroes();
62+
}
5863
}
5964
// #enddocregion example

public/docs/_examples/style-guide/ts/05-04/app/heroes/heroes.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div>
33
<h2>My Heroes</h2>
44
<ul class="heroes">
5-
<li *ngFor="let hero of heroes">
5+
<li *ngFor="let hero of heroes | async" (click)="selectedHero=hero">
66
<span class="badge">{{hero.id}}</span> {{hero.name}}
77
</li>
88
</ul>
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
// #docplaster
2-
// #docregion
31
import { Component, OnInit } from '@angular/core';
2+
import { Observable } from 'rxjs/Observable';
43

5-
import { Hero } from './shared';
4+
import { Hero, HeroService } from './shared';
65

76
// #docregion example
87
@Component({
9-
// #enddocregion example
108
moduleId: module.id,
11-
// #docregion example
129
selector: 'toh-heroes',
1310
templateUrl: './heroes.component.html',
1411
styleUrls: ['./heroes.component.css']
1512
})
1613
export class HeroesComponent implements OnInit {
17-
heroes: Hero[];
14+
heroes: Observable<Hero[]>;
1815
selectedHero: Hero;
1916

20-
ngOnInit() { }
17+
constructor(private heroService: HeroService) { }
18+
19+
ngOnInit() {
20+
this.heroes = this.heroService.getHeroes();
21+
}
2122
}
2223
// #enddocregion example
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Injectable } from '@angular/core';
2+
import { Http } from '@angular/http';
3+
4+
import { Observable } from 'rxjs/Observable';
5+
import 'rxjs/add/operator/map';
6+
7+
import { Hero } from './hero.model';
8+
9+
@Injectable()
10+
export class HeroService {
11+
12+
constructor(private http: Http) {}
13+
14+
getHeroes(): Observable<Hero[]> {
15+
return this.http.get('api/heroes')
16+
.map(resp => resp.json().data as Hero[]);
17+
}
18+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './hero.model';
2+
export * from './hero.service';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
<!-- #docregion -->
22
<toh-hero-button label="OK" (change)="doSomething()">
33
</toh-hero-button>
4+
5+
<!-- `heroHighlight` is both the directive name and the data-bound aliased property name -->
6+
<h3 heroHighlight="skyblue">The Great Bombasto</h3>

public/docs/_examples/style-guide/ts/05-13/app/app.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { NgModule } from '@angular/core';
22
import { RouterModule } from '@angular/router';
33

44
import { AppComponent } from './app.component';
5-
import { HeroButtonComponent } from './heroes';
5+
import { HeroButtonComponent, HeroHighlightDirective } from './heroes';
66

77
@NgModule({
88
imports: [
99
RouterModule.forChild([{ path: '05-13', component: AppComponent }])
1010
],
1111
declarations: [
1212
AppComponent,
13-
HeroButtonComponent
13+
HeroButtonComponent, HeroHighlightDirective
1414
],
1515
exports: [ AppComponent ]
1616
})

public/docs/_examples/style-guide/ts/05-13/app/heroes/shared/hero-button/hero-button.component.avoid.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
// #docregion
21
import { Component, EventEmitter, Input, Output } from '@angular/core';
32
// #docregion example
4-
/* avoid */
3+
/* avoid pointless aliasing */
54

65
@Component({
76
selector: 'toh-hero-button',
87
template: `<button>{{label}}</button>`
98
})
109
export class HeroButtonComponent {
10+
// Pointless aliases
1111
@Output('changeEvent') change = new EventEmitter<any>();
1212
@Input('labelAttribute') label: string;
1313
}

0 commit comments

Comments
 (0)