docs(aio): rename cb- files and a few others
This commit is contained in:

committed by
Pete Bacon Darwin

parent
c3fa8803d3
commit
93516ea8a1
@ -0,0 +1,10 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
import { HeroService } from './heroes';
|
||||
|
||||
@Component({
|
||||
selector: 'sg-app',
|
||||
template: '<toh-hero-list></toh-hero-list>',
|
||||
providers: [HeroService]
|
||||
})
|
||||
export class AppComponent { }
|
19
aio/content/examples/styleguide/src/05-15/app/app.module.ts
Normal file
19
aio/content/examples/styleguide/src/05-15/app/app.module.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { RouterModule } from '@angular/router';
|
||||
|
||||
import { AppComponent } from './app.component';
|
||||
import { HeroListComponent } from './heroes';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
BrowserModule,
|
||||
RouterModule.forChild([{ path: '05-15', component: AppComponent }])
|
||||
],
|
||||
declarations: [
|
||||
AppComponent,
|
||||
HeroListComponent
|
||||
],
|
||||
exports: [ AppComponent ]
|
||||
})
|
||||
export class AppModule {}
|
@ -0,0 +1,39 @@
|
||||
// #docregion
|
||||
/* avoid */
|
||||
|
||||
import { OnInit } from '@angular/core';
|
||||
import { Http, Response } from '@angular/http';
|
||||
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import 'rxjs/add/operator/catch';
|
||||
import 'rxjs/add/operator/finally';
|
||||
import 'rxjs/add/operator/map';
|
||||
|
||||
import { Hero } from '../shared/hero.model';
|
||||
|
||||
const heroesUrl = 'http://angular.io';
|
||||
|
||||
export class HeroListComponent implements OnInit {
|
||||
heroes: Hero[];
|
||||
constructor(private http: Http) {}
|
||||
getHeroes() {
|
||||
this.heroes = [];
|
||||
this.http.get(heroesUrl)
|
||||
.map((response: Response) => <Hero[]>response.json().data)
|
||||
.catch(this.catchBadResponse)
|
||||
.finally(() => this.hideSpinner())
|
||||
.subscribe((heroes: Hero[]) => this.heroes = heroes);
|
||||
}
|
||||
ngOnInit() {
|
||||
this.getHeroes();
|
||||
}
|
||||
|
||||
private catchBadResponse(err: any, source: Observable<any>) {
|
||||
// log and handle the exception
|
||||
return new Observable();
|
||||
}
|
||||
|
||||
private hideSpinner() {
|
||||
// hide the spinner
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
// #docregion example
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
|
||||
import { Hero, HeroService } from '../shared';
|
||||
|
||||
@Component({
|
||||
selector: 'toh-hero-list',
|
||||
template: `...`
|
||||
})
|
||||
export class HeroListComponent implements OnInit {
|
||||
heroes: Hero[];
|
||||
constructor(private heroService: HeroService) {}
|
||||
getHeroes() {
|
||||
this.heroes = [];
|
||||
this.heroService.getHeroes()
|
||||
.subscribe(heroes => this.heroes = heroes);
|
||||
}
|
||||
ngOnInit() {
|
||||
this.getHeroes();
|
||||
}
|
||||
}
|
||||
// #enddocregion example
|
||||
|
@ -0,0 +1 @@
|
||||
export * from './hero-list.component';
|
@ -0,0 +1,2 @@
|
||||
export * from './hero-list';
|
||||
export * from './shared';
|
@ -0,0 +1,5 @@
|
||||
// #docregion
|
||||
export class Hero {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
// #docregion
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import 'rxjs/add/observable/of';
|
||||
|
||||
import { Hero } from './hero.model';
|
||||
|
||||
@Injectable()
|
||||
export class HeroService {
|
||||
getHeroes() {
|
||||
let heroes: Hero[] = [];
|
||||
return Observable.of(heroes);
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
// #docregion
|
||||
export * from './hero.model';
|
||||
export * from './hero.service';
|
2
aio/content/examples/styleguide/src/05-15/app/index.ts
Normal file
2
aio/content/examples/styleguide/src/05-15/app/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './heroes';
|
||||
export * from './app.component';
|
Reference in New Issue
Block a user