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

Commit 0d58e09

Browse files
Cleaned up error handling example
1 parent 4bec612 commit 0d58e09

22 files changed

+151
-533
lines changed

public/docs/_examples/rxjs/ts/src/app/add-hero.component.html

Lines changed: 0 additions & 15 deletions
This file was deleted.

public/docs/_examples/rxjs/ts/src/app/add-hero.component.ts

Lines changed: 0 additions & 74 deletions
This file was deleted.

public/docs/_examples/rxjs/ts/src/app/api-error-handler.service.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

public/docs/_examples/rxjs/ts/src/app/app-routing.module.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,12 @@
22
// #docregion
33
import { NgModule } from '@angular/core';
44
import { RouterModule, Routes } from '@angular/router';
5-
import { AddHeroComponent } from './add-hero.component';
6-
import { HeroDetailComponent } from './hero-detail.component';
7-
import { HeroSearchComponent } from './hero-search.component';
85
import { HeroListComponent } from './hero-list.component';
96
import { HeroCounterComponent } from './hero-counter.component';
107

118
const appRoutes: Routes = [
12-
{ path: 'heroes/add', component: AddHeroComponent },
13-
{ path: 'heroes/search', component: HeroSearchComponent },
149
{ path: 'hero/counter', component: HeroCounterComponent },
1510
{ path: 'heroes', component: HeroListComponent },
16-
{ path: 'hero/:id', component: HeroDetailComponent },
1711
{ path: '', redirectTo: '/heroes', pathMatch: 'full' },
1812
];
1913

public/docs/_examples/rxjs/ts/src/app/app.component.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import { EventAggregatorService } from './event-aggregator.service';
1010
1111
<a routerLink="/heroes">Heroes</a><br>
1212
<a routerLink="/hero/counter">Hero Counter</a><br>
13-
<a routerLink="/heroes/add">Add Hero</a><br>
14-
<a routerLink="/heroes/search">Hero Search</a>
1513
1614
<router-outlet></router-outlet>
1715

public/docs/_examples/rxjs/ts/src/app/app.module.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,17 @@ import { ReactiveFormsModule } from '@angular/forms';
66

77
import { AppComponent } from './app.component';
88
import { AppRoutingModule } from './app-routing.module';
9-
import { AddHeroComponent } from './add-hero.component';
10-
import { LoadingComponent } from './loading.component';
11-
import { HeroSearchComponent } from './hero-search.component';
12-
import { HeroDetailComponent } from './hero-detail.component';
139
import { HeroListComponent } from './hero-list.component';
1410
import { HeroCounterComponent } from './hero-counter.component';
1511
import { MessageLogComponent } from './message-log.component';
12+
import { LoadingComponent } from './loading.component';
1613

1714
import { LoadingService } from './loading.service';
1815
import { HeroService } from './hero.service';
1916

2017
// #docregion event-aggregator-import
2118
import { EventAggregatorService } from './event-aggregator.service';
2219
// #enddocregion event-aggregator-import
23-
import { ApiErrorHandlerService } from './api-error-handler.service';
2420

2521
// Imports for loading & configuring the in-memory web api
2622
import { InMemoryWebApiModule } from 'angular-in-memory-web-api';
@@ -36,19 +32,15 @@ import { InMemoryDataService } from './in-memory-data.service';
3632
],
3733
declarations: [
3834
AppComponent,
39-
AddHeroComponent,
40-
LoadingComponent,
41-
HeroSearchComponent,
42-
HeroDetailComponent,
43-
HeroListComponent,
4435
HeroCounterComponent,
45-
MessageLogComponent
36+
HeroListComponent,
37+
MessageLogComponent,
38+
LoadingComponent
4639
],
4740
providers: [
4841
HeroService,
4942
LoadingService,
50-
EventAggregatorService,
51-
ApiErrorHandlerService
43+
EventAggregatorService
5244
],
5345
bootstrap: [ AppComponent ]
5446
})

public/docs/_examples/rxjs/ts/src/app/hero-counter.component.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,19 @@ export class HeroCounterComponent implements OnInit, OnDestroy {
3737
}, 1000);
3838
});
3939

40-
this.counter$
40+
let counter1Sub = this.counter$
41+
.takeUntil(this.onDestroy$)
42+
.subscribe();
43+
44+
let counter2Sub = this.counter$
45+
.takeUntil(this.onDestroy$)
46+
.subscribe();
47+
48+
let counter3Sub = this.counter$
4149
.takeUntil(this.onDestroy$)
4250
.subscribe();
4351
}
44-
52+
4553
// #docregion ngOnDestroy-complete
4654
ngOnDestroy() {
4755
this.onDestroy$.complete();

public/docs/_examples/rxjs/ts/src/app/hero-detail.component.1.ts

Lines changed: 0 additions & 56 deletions
This file was deleted.

public/docs/_examples/rxjs/ts/src/app/hero-detail.component.ts

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
// #docplaster
22
// #docregion
3-
// #docregion retry-operator
4-
import 'rxjs/add/operator/retry';
5-
// #enddocregion retry-operator
6-
import 'rxjs/add/observable/of';
7-
// #docregion failed-heroes
83
import { Component, OnInit } from '@angular/core';
94
import { Observable } from 'rxjs/Observable';
105

116
import { HeroService } from './hero.service';
127
import { Hero } from './hero';
138

149
@Component({
10+
// #docregion async-pipe
1511
template: `
1612
<h2>HEROES</h2>
1713
<ul class="items">
@@ -20,7 +16,9 @@ import { Hero } from './hero';
2016
</li>
2117
</ul>
2218
`
19+
// #enddocregion async-pipe
2320
})
21+
// #docregion observable-heroes
2422
export class HeroListComponent implements OnInit {
2523
heroes$: Observable<Hero[]>;
2624

@@ -29,15 +27,7 @@ export class HeroListComponent implements OnInit {
2927
) {}
3028

3129
ngOnInit() {
32-
// #docregion failed-heroes
33-
this.heroes$ = this.service.getFailedHeroes()
34-
// #enddocregion failed-heroes
35-
.catch((error: any) => {
36-
console.log(`An error occurred: ${error}`);
37-
38-
return Observable.of([]);
39-
});
40-
// #docregion failed-heroes
30+
this.heroes$ = this.service.getHeroes();
4131
}
4232
}
4333
// #enddocregion

0 commit comments

Comments
 (0)