Skip to content

Commit 5c5c9ca

Browse files
brandonrobertswardbell
authored andcommitted
fix(toh-5): Fixed issues in tutorial flow
The HeroDetailComponent should be in the module declarations from the beginning. InMemoryWebApiModule.forRoot(InMemoryDataService) and correct text
1 parent a35fcb4 commit 5c5c9ca

File tree

7 files changed

+53
-59
lines changed

7 files changed

+53
-59
lines changed

public/docs/_examples/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"@angular/router": "3.0.0-rc.1",
3636
"@angular/router-deprecated": "2.0.0-rc.2",
3737
"@angular/upgrade": "2.0.0-rc.5",
38-
"angular2-in-memory-web-api": "0.0.15",
38+
"angular2-in-memory-web-api": "0.0.17",
3939
"bootstrap": "^3.3.6",
4040
"core-js": "^2.4.0",
4141
"reflect-metadata": "^0.1.3",

public/docs/_examples/toh-5/ts/app/app.module.1.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ import { NgModule } from '@angular/core';
33
import { BrowserModule } from '@angular/platform-browser';
44
import { FormsModule } from '@angular/forms';
55

6-
import { AppComponent } from './app.component';
7-
8-
import { HeroesComponent } from './heroes.component';
9-
10-
import { HeroService } from './hero.service';
6+
import { AppComponent } from './app.component';
7+
import { HeroDetailComponent } from './hero-detail.component';
8+
import { HeroesComponent } from './heroes.component';
9+
import { HeroService } from './hero.service';
1110

1211
@NgModule({
1312
imports: [
@@ -16,6 +15,7 @@ import { HeroService } from './hero.service';
1615
],
1716
declarations: [
1817
AppComponent,
18+
HeroDetailComponent,
1919
HeroesComponent
2020
],
2121
providers: [

public/docs/_examples/toh-5/ts/app/app.module.ts

+7-12
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ import { NgModule } from '@angular/core';
44
import { BrowserModule } from '@angular/platform-browser';
55
import { FormsModule } from '@angular/forms';
66

7-
import { AppComponent } from './app.component';
8-
// #docregion routing
9-
import { routing } from './app.routing';
10-
// #enddocregion routing
11-
12-
import { HeroesComponent } from './heroes.component';
7+
import { AppComponent } from './app.component';
138
import { DashboardComponent } from './dashboard.component';
149
import { HeroDetailComponent } from './hero-detail.component';
15-
16-
import { HeroService } from './hero.service';
10+
import { HeroesComponent } from './heroes.component';
11+
import { HeroService } from './hero.service';
12+
// #docregion routing
13+
import { routing } from './app.routing';
1714
// #docregion routing
1815

1916
@NgModule({
@@ -26,11 +23,9 @@ import { HeroService } from './hero.service';
2623
// #docregion dashboard, hero-detail
2724
declarations: [
2825
AppComponent,
29-
HeroesComponent,
3026
DashboardComponent,
31-
// #enddocregion dashboard
32-
HeroDetailComponent
33-
// #docregion dashboard
27+
HeroDetailComponent,
28+
HeroesComponent
3429
],
3530
// #enddocregion dashboard, hero-detail
3631
providers: [

public/docs/_examples/toh-6/ts/app/app.module.ts

+19-23
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,51 @@
11
// #docplaster
22
// #docregion , v1, v2
3-
import { NgModule } from '@angular/core';
4-
import { BrowserModule } from '@angular/platform-browser';
5-
import { FormsModule } from '@angular/forms';
6-
import { HttpModule } from '@angular/http';
3+
import { NgModule } from '@angular/core';
4+
import { BrowserModule } from '@angular/platform-browser';
5+
import { FormsModule } from '@angular/forms';
6+
import { HttpModule } from '@angular/http';
77

88
// #enddocregion v1
99
// Imports for loading & configuring the in-memory web api
10-
import { XHRBackend } from '@angular/http';
11-
12-
import { InMemoryBackendService, SEED_DATA } from 'angular2-in-memory-web-api';
13-
import { InMemoryDataService } from './in-memory-data.service';
10+
import { InMemoryWebApiModule } from 'angular2-in-memory-web-api';
11+
import { InMemoryDataService } from './in-memory-data.service';
1412

1513
// #docregion v1
16-
import { AppComponent } from './app.component';
17-
import { routing } from './app.routing';
18-
19-
import { HeroesComponent } from './heroes.component';
14+
import { AppComponent } from './app.component';
2015
import { DashboardComponent } from './dashboard.component';
16+
import { HeroesComponent } from './heroes.component';
2117
import { HeroDetailComponent } from './hero-detail.component';
2218
import { HeroService } from './hero.service';
2319
// #enddocregion v1, v2
24-
// #docregion search
2520
import { HeroSearchComponent } from './hero-search.component';
2621
// #docregion v1, v2
22+
import { routing } from './app.routing';
2723

28-
// #enddocregion search
2924
@NgModule({
3025
imports: [
3126
BrowserModule,
3227
FormsModule,
33-
routing,
34-
HttpModule
28+
HttpModule,
29+
// #enddocregion v1
30+
// #docregion in-mem-web-api
31+
InMemoryWebApiModule.forRoot(InMemoryDataService),
32+
// #enddocregion in-mem-web-api
33+
// #docregion v1
34+
routing
3535
],
3636
// #docregion search
3737
declarations: [
3838
AppComponent,
39-
HeroesComponent,
4039
DashboardComponent,
4140
HeroDetailComponent,
42-
// #enddocregion v1, v2
41+
HeroesComponent,
42+
// #enddocregion v1, v2
4343
HeroSearchComponent
44-
// #docregion v1, v2
44+
// #docregion v1, v2
4545
],
4646
// #enddocregion search
4747
providers: [
4848
HeroService,
49-
// #enddocregion v1
50-
{ provide: XHRBackend, useClass: InMemoryBackendService }, // in-mem server
51-
{ provide: SEED_DATA, useClass: InMemoryDataService } // in-mem server data
52-
// #docregion v1
5349
],
5450
bootstrap: [ AppComponent ]
5551
})

public/docs/_examples/toh-6/ts/app/in-memory-data.service.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// #docregion , init
2-
export class InMemoryDataService {
2+
import { InMemoryDbService } from 'angular2-in-memory-web-api';
3+
export class InMemoryDataService implements InMemoryDbService {
34
createDb() {
45
let heroes = [
56
{id: 11, name: 'Mr. Nice'},

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

+4-9
Original file line numberDiff line numberDiff line change
@@ -479,15 +479,10 @@ code-example(format='').
479479
The colon (:) in the path indicates that `:id` is a placeholder to be filled with a specific hero `id`
480480
when navigating to the `HeroDetailComponent`.
481481

482-
.l-sub-section
483-
:marked
484-
Remember to import the hero detail component before creating this route.
485-
486-
+ifDocsFor('ts|js')
487-
:marked
488-
Add the `HeroDetailComponent` to our root NgModule's `declarations`.
489-
490-
+makeExcerpt('app/app.module.ts', 'hero-detail')
482+
+ifDocsFor('dart')
483+
.l-sub-section
484+
:marked
485+
Remember to import the hero detail component before creating this route.
491486

492487
:marked
493488
We're finished with the application routes.

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

+15-8
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ block http-providers
5959
So we register them in the `imports` array of `app.module.ts` where we
6060
bootstrap the application and its root `AppComponent`.
6161

62-
+makeExcerpt('app/app.module.ts (v1)')
62+
+makeExample('app/app.module.ts', 'v1','app/app.module.ts (v1)')
6363

6464
:marked
6565
Notice that we supply `!{_HttpModule}` as part of the *imports* !{_array} in root NgModule `AppModule`.
@@ -88,10 +88,16 @@ block http-providers
8888

8989
block backend
9090
:marked
91-
We're replacing the default `XHRBackend`, the service that talks to the remote server,
92-
with the in-memory web API service after priming it as follows:
91+
We're importing the `InMemoryWebApiModule` and adding it to the module `imports`.
92+
The `InMemoryWebApiModule` replaces the default `Http` client backend —
93+
the supporting service that talks to the remote server —
94+
with an _in-memory web API alternative service_.
95+
+makeExcerpt(_appModuleTsVsMainTs, 'in-mem-web-api', '')
96+
:marked
97+
The `forRoot` configuration method takes an `InMemoryDataService` class
98+
that will prime the in-memory database as follows:
9399

94-
+makeExample('app/in-memory-data.service.ts', 'init')
100+
+makeExample('app/in-memory-data.service.ts', 'init')(format='.')
95101

96102
p This file replaces the #[code #[+adjExPath('mock-heroes.ts')]] which is now safe to delete.
97103

@@ -500,24 +506,25 @@ block observable-transformers
500506
We take a different approach in this example.
501507
We combine all of the RxJS `Observable` extensions that _our entire app_ requires into a single RxJS imports file.
502508

503-
+makeExample('app/rxjs-extensions.ts')
509+
+makeExample('app/rxjs-extensions.ts')(format='.')
504510

505511
:marked
506512
We load them all at once by importing `rxjs-extensions` in `AppComponent`.
507513

508-
+makeExcerpt('app/app.component.ts', 'rxjs-extensions')
514+
+makeExcerpt('app/app.component.ts', 'rxjs-extensions')(format='.')
509515

510516
:marked
511517
### Add the search component to the dashboard
512518

513519
We add the hero search HTML element to the bottom of the `DashboardComponent` template.
514520

515-
+makeExample('app/dashboard.component.html')
521+
+makeExample('app/dashboard.component.html')(format='.')
516522

517523
- var _declarations = _docsFor == 'dart' ? 'directives' : 'declarations'
518524
- var declFile = _docsFor == 'dart' ? 'app/dashboard.component.ts' : 'app/app.module.ts'
519525
:marked
520-
And finally, we import the `HeroSearchComponent` and add it to the `!{_declarations}` !{_array}:
526+
And finally, we import the `HeroSearchComponent` from `'./hero-search.component.ts'`
527+
and add it to the `!{_declarations}` !{_array}:
521528

522529
+makeExcerpt(declFile, 'search')
523530

0 commit comments

Comments
 (0)