docs: update all docs to partially comply the style-guide
This commit is contained in:
parent
2ccdd867d2
commit
596825a8b1
@ -1,4 +1,5 @@
|
|||||||
import { Injectable, Type } from '@angular/core';
|
import { Injectable, Type } from '@angular/core';
|
||||||
|
|
||||||
import { Logger } from './logger.service';
|
import { Logger } from './logger.service';
|
||||||
import { Hero } from './hero';
|
import { Hero } from './hero';
|
||||||
|
|
||||||
@ -10,7 +11,7 @@ const HEROES = [
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BackendService {
|
export class BackendService {
|
||||||
constructor(private _logger: Logger) {}
|
constructor(private logger: Logger) {}
|
||||||
|
|
||||||
getAll(type:Type) : PromiseLike<any[]>{
|
getAll(type:Type) : PromiseLike<any[]>{
|
||||||
if (type === Hero) {
|
if (type === Hero) {
|
||||||
@ -18,7 +19,7 @@ export class BackendService {
|
|||||||
return Promise.resolve<Hero[]>(HEROES);
|
return Promise.resolve<Hero[]>(HEROES);
|
||||||
}
|
}
|
||||||
let err = new Error('Cannot get object of this type');
|
let err = new Error('Cannot get object of this type');
|
||||||
this._logger.error(err);
|
this.logger.error(err);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
import { Component, Input} from '@angular/core';
|
import { Component, Input} from '@angular/core';
|
||||||
|
|
||||||
import { Hero } from './hero';
|
import { Hero } from './hero';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docplaster
|
// #docplaster
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
|
||||||
import { Hero } from './hero';
|
import { Hero } from './hero';
|
||||||
import { HeroDetailComponent } from './hero-detail.component';
|
import { HeroDetailComponent } from './hero-detail.component';
|
||||||
import { HeroService } from './hero.service';
|
import { HeroService } from './hero.service';
|
||||||
@ -24,14 +25,14 @@ export class HeroesComponent { ... }
|
|||||||
// #docregion class
|
// #docregion class
|
||||||
export class HeroListComponent implements OnInit {
|
export class HeroListComponent implements OnInit {
|
||||||
// #docregion ctor
|
// #docregion ctor
|
||||||
constructor(private _service: HeroService) { }
|
constructor(private service: HeroService) { }
|
||||||
// #enddocregion ctor
|
// #enddocregion ctor
|
||||||
|
|
||||||
heroes: Hero[];
|
heroes: Hero[];
|
||||||
selectedHero: Hero;
|
selectedHero: Hero;
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.heroes = this._service.getHeroes();
|
this.heroes = this.service.getHeroes();
|
||||||
}
|
}
|
||||||
|
|
||||||
selectHero(hero: Hero) { this.selectedHero = hero; }
|
selectHero(hero: Hero) { this.selectedHero = hero; }
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { Hero } from './hero';
|
import { Hero } from './hero';
|
||||||
import { BackendService } from './backend.service';
|
import { BackendService } from './backend.service';
|
||||||
import { Logger } from './logger.service';
|
import { Logger } from './logger.service';
|
||||||
@ -8,18 +9,18 @@ import {Logger} from './logger.service';
|
|||||||
export class HeroService {
|
export class HeroService {
|
||||||
// #docregion ctor
|
// #docregion ctor
|
||||||
constructor(
|
constructor(
|
||||||
private _backend: BackendService,
|
private backend: BackendService,
|
||||||
private _logger: Logger) { }
|
private logger: Logger) { }
|
||||||
// #enddocregion ctor
|
// #enddocregion ctor
|
||||||
|
|
||||||
private _heroes: Hero[] = [];
|
private heroes: Hero[] = [];
|
||||||
|
|
||||||
getHeroes() {
|
getHeroes() {
|
||||||
this._backend.getAll(Hero).then( (heroes: Hero[]) => {
|
this.backend.getAll(Hero).then( (heroes: Hero[]) => {
|
||||||
this._logger.log(`Fetched ${heroes.length} heroes.`);
|
this.logger.log(`Fetched ${heroes.length} heroes.`);
|
||||||
this._heroes.push(...heroes); // fill cache
|
this.heroes.push(...heroes); // fill cache
|
||||||
});
|
});
|
||||||
return this._heroes;
|
return this.heroes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// #enddocregion class
|
// #enddocregion class
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { SalesTaxService } from './sales-tax.service';
|
import { SalesTaxService } from './sales-tax.service';
|
||||||
import { TaxRateService } from './tax-rate.service';
|
import { TaxRateService } from './tax-rate.service';
|
||||||
|
|
||||||
@ -31,11 +32,11 @@ export class SalesTaxComponent { ... }
|
|||||||
// #docregion class
|
// #docregion class
|
||||||
export class SalesTaxComponent {
|
export class SalesTaxComponent {
|
||||||
// #docregion ctor
|
// #docregion ctor
|
||||||
constructor(private _salesTaxService: SalesTaxService) { }
|
constructor(private salesTaxService: SalesTaxService) { }
|
||||||
// #enddocregion ctor
|
// #enddocregion ctor
|
||||||
|
|
||||||
getTax(value:string | number){
|
getTax(value:string | number){
|
||||||
return this._salesTaxService.getVAT(value);
|
return this.salesTaxService.getVAT(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// #enddocregion class
|
// #enddocregion class
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import {Injectable, Inject} from '@angular/core';
|
import { Inject, Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { TaxRateService } from './tax-rate.service';
|
import { TaxRateService } from './tax-rate.service';
|
||||||
|
|
||||||
// #docregion class
|
// #docregion class
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SalesTaxService {
|
export class SalesTaxService {
|
||||||
constructor(private _rateService: TaxRateService) { }
|
constructor(private rateService: TaxRateService) { }
|
||||||
getVAT(value:string | number){
|
getVAT(value:string | number){
|
||||||
let amount:number;
|
let amount:number;
|
||||||
if (typeof value === "string"){
|
if (typeof value === "string"){
|
||||||
@ -13,7 +14,7 @@ export class SalesTaxService {
|
|||||||
} else {
|
} else {
|
||||||
amount = value;
|
amount = value;
|
||||||
}
|
}
|
||||||
return (amount || 0) * this._rateService.getRate('VAT');
|
return (amount || 0) * this.rateService.getRate('VAT');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// #enddocregion class
|
// #enddocregion class
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { HighlightDirective } from './highlight.directive';
|
import { HighlightDirective } from './highlight.directive';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -14,16 +14,16 @@ import {Directive, ElementRef, Input} from '@angular/core';
|
|||||||
export class HighlightDirective {
|
export class HighlightDirective {
|
||||||
|
|
||||||
// #docregion ctor
|
// #docregion ctor
|
||||||
private _el:HTMLElement;
|
private el:HTMLElement;
|
||||||
constructor(el: ElementRef) { this._el = el.nativeElement; }
|
constructor(el: ElementRef) { this.el = el.nativeElement; }
|
||||||
// #enddocregion ctor
|
// #enddocregion ctor
|
||||||
|
|
||||||
// #docregion mouse-methods
|
// #docregion mouse-methods
|
||||||
onMouseEnter() { this._highlight("yellow"); }
|
onMouseEnter() { this.highlight("yellow"); }
|
||||||
onMouseLeave() { this._highlight(null); }
|
onMouseLeave() { this.highlight(null); }
|
||||||
|
|
||||||
private _highlight(color: string) {
|
private highlight(color: string) {
|
||||||
this._el.style.backgroundColor = color;
|
this.el.style.backgroundColor = color;
|
||||||
}
|
}
|
||||||
// #enddocregion mouse-methods
|
// #enddocregion mouse-methods
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ import {Directive, ElementRef, Input} from '@angular/core';
|
|||||||
export class HighlightDirective {
|
export class HighlightDirective {
|
||||||
|
|
||||||
private _defaultColor = 'red';
|
private _defaultColor = 'red';
|
||||||
private _el:HTMLElement;
|
private el:HTMLElement;
|
||||||
// #enddocregion class-1
|
// #enddocregion class-1
|
||||||
// #enddocregion full
|
// #enddocregion full
|
||||||
/*
|
/*
|
||||||
@ -37,15 +37,15 @@ export class HighlightDirective {
|
|||||||
|
|
||||||
// #enddocregion class-1
|
// #enddocregion class-1
|
||||||
// #docregion class-1
|
// #docregion class-1
|
||||||
constructor(el: ElementRef) { this._el = el.nativeElement; }
|
constructor(el: ElementRef) { this.el = el.nativeElement; }
|
||||||
|
|
||||||
// #docregion mouse-enter
|
// #docregion mouse-enter
|
||||||
onMouseEnter() { this._highlight(this.highlightColor || this._defaultColor); }
|
onMouseEnter() { this.highlight(this.highlightColor || this._defaultColor); }
|
||||||
// #enddocregion mouse-enter
|
// #enddocregion mouse-enter
|
||||||
onMouseLeave() { this._highlight(null); }
|
onMouseLeave() { this.highlight(null); }
|
||||||
|
|
||||||
private _highlight(color:string) {
|
private highlight(color:string) {
|
||||||
this._el.style.backgroundColor = color;
|
this.el.style.backgroundColor = color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// #enddocregion class-1
|
// #enddocregion class-1
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { bootstrap } from '@angular/platform-browser-dynamic';
|
import { bootstrap } from '@angular/platform-browser-dynamic';
|
||||||
|
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
|
||||||
bootstrap(AppComponent);
|
bootstrap(AppComponent);
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { bootstrap } from '@angular/platform-browser-dynamic';
|
import { bootstrap } from '@angular/platform-browser-dynamic';
|
||||||
|
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
|
||||||
bootstrap(AppComponent);
|
bootstrap(AppComponent);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { IMovie } from './movie';
|
import { IMovie } from './movie';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { HeroParentComponent } from './hero-parent.component';
|
import { HeroParentComponent } from './hero-parent.component';
|
||||||
import { NameParentComponent } from './name-parent.component';
|
import { NameParentComponent } from './name-parent.component';
|
||||||
import { VersionParentComponent } from './version-parent.component';
|
import { VersionParentComponent } from './version-parent.component';
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component, Input, OnDestroy } from '@angular/core';
|
import { Component, Input, OnDestroy } from '@angular/core';
|
||||||
|
|
||||||
import { MissionService } from './mission.service';
|
import { MissionService } from './mission.service';
|
||||||
import { Subscription } from 'rxjs/Subscription';
|
import { Subscription } from 'rxjs/Subscription';
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ export class CountdownLocalVarParentComponent { }
|
|||||||
export class CountdownViewChildParentComponent implements AfterViewInit {
|
export class CountdownViewChildParentComponent implements AfterViewInit {
|
||||||
|
|
||||||
@ViewChild(CountdownTimerComponent)
|
@ViewChild(CountdownTimerComponent)
|
||||||
private _timerComponent:CountdownTimerComponent;
|
private timerComponent:CountdownTimerComponent;
|
||||||
|
|
||||||
seconds() { return 0; }
|
seconds() { return 0; }
|
||||||
|
|
||||||
@ -50,10 +50,10 @@ export class CountdownViewChildParentComponent implements AfterViewInit {
|
|||||||
// Redefine `seconds()` to get from the `CountdownTimerComponent.seconds` ...
|
// Redefine `seconds()` to get from the `CountdownTimerComponent.seconds` ...
|
||||||
// but wait a tick first to avoid one-time devMode
|
// but wait a tick first to avoid one-time devMode
|
||||||
// unidirectional-data-flow-violation error
|
// unidirectional-data-flow-violation error
|
||||||
setTimeout(() => this.seconds = () => this._timerComponent.seconds, 0)
|
setTimeout(() => this.seconds = () => this.timerComponent.seconds, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
start(){ this._timerComponent.start(); }
|
start(){ this.timerComponent.start(); }
|
||||||
stop() { this._timerComponent.stop(); }
|
stop() { this.timerComponent.stop(); }
|
||||||
}
|
}
|
||||||
// #enddocregion vc
|
// #enddocregion vc
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import {Component, OnInit, OnDestroy} from '@angular/core';
|
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector:'countdown-timer',
|
selector:'countdown-timer',
|
||||||
@ -16,13 +16,13 @@ export class CountdownTimerComponent implements OnInit, OnDestroy {
|
|||||||
ngOnInit() { this.start(); }
|
ngOnInit() { this.start(); }
|
||||||
ngOnDestroy() { this.clearTimer(); }
|
ngOnDestroy() { this.clearTimer(); }
|
||||||
|
|
||||||
start() { this._countDown(); }
|
start() { this.countDown(); }
|
||||||
stop() {
|
stop() {
|
||||||
this.clearTimer();
|
this.clearTimer();
|
||||||
this.message = `Holding at T-${this.seconds} seconds`;
|
this.message = `Holding at T-${this.seconds} seconds`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _countDown() {
|
private countDown() {
|
||||||
this.clearTimer();
|
this.clearTimer();
|
||||||
this.intervalId = setInterval(()=>{
|
this.intervalId = setInterval(()=>{
|
||||||
this.seconds -= 1;
|
this.seconds -= 1;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component, Input } from '@angular/core';
|
import { Component, Input } from '@angular/core';
|
||||||
|
|
||||||
import { Hero } from './hero';
|
import { Hero } from './hero';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { HeroChildComponent } from './hero-child.component';
|
import { HeroChildComponent } from './hero-child.component';
|
||||||
import { HEROES } from './hero';
|
import { HEROES } from './hero';
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { bootstrap } from '@angular/platform-browser-dynamic';
|
import { bootstrap } from '@angular/platform-browser-dynamic';
|
||||||
|
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
|
||||||
bootstrap(AppComponent);
|
bootstrap(AppComponent);
|
@ -6,20 +6,20 @@ import {Subject} from 'rxjs/Subject';
|
|||||||
export class MissionService {
|
export class MissionService {
|
||||||
|
|
||||||
// Observable string sources
|
// Observable string sources
|
||||||
private _missionAnnouncedSource = new Subject<string>();
|
private missionAnnouncedSource = new Subject<string>();
|
||||||
private _missionConfirmedSource = new Subject<string>();
|
private missionConfirmedSource = new Subject<string>();
|
||||||
|
|
||||||
// Observable string streams
|
// Observable string streams
|
||||||
missionAnnounced$ = this._missionAnnouncedSource.asObservable();
|
missionAnnounced$ = this.missionAnnouncedSource.asObservable();
|
||||||
missionConfirmed$ = this._missionConfirmedSource.asObservable();
|
missionConfirmed$ = this.missionConfirmedSource.asObservable();
|
||||||
|
|
||||||
// Service message commands
|
// Service message commands
|
||||||
announceMission(mission: string) {
|
announceMission(mission: string) {
|
||||||
this._missionAnnouncedSource.next(mission)
|
this.missionAnnouncedSource.next(mission)
|
||||||
}
|
}
|
||||||
|
|
||||||
confirmMission(astronaut: string) {
|
confirmMission(astronaut: string) {
|
||||||
this._missionConfirmedSource.next(astronaut);
|
this.missionConfirmedSource.next(astronaut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// #enddocregion
|
// #enddocregion
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { AstronautComponent } from './astronaut.component';
|
import { AstronautComponent } from './astronaut.component';
|
||||||
import { MissionService } from './mission.service';
|
import { MissionService } from './mission.service';
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { NameChildComponent } from './name-child.component';
|
import { NameChildComponent } from './name-child.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { VersionChildComponent } from './version-child.component';
|
import { VersionChildComponent } from './version-child.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { VoterComponent } from './voter.component';
|
import { VoterComponent } from './voter.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/* tslint:disable:one-line:check-open-brace*/
|
/* tslint:disable:one-line:check-open-brace*/
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { LoggerService } from './logger.service';
|
import { LoggerService } from './logger.service';
|
||||||
|
|
||||||
// #docregion minimal-logger
|
// #docregion minimal-logger
|
||||||
|
@ -20,10 +20,10 @@ export class HeroBioComponent implements OnInit {
|
|||||||
|
|
||||||
@Input() heroId:number;
|
@Input() heroId:number;
|
||||||
|
|
||||||
constructor(private _heroCache:HeroCacheService) { }
|
constructor(private heroCache:HeroCacheService) { }
|
||||||
|
|
||||||
ngOnInit() { this._heroCache.fetchCachedHero(this.heroId); }
|
ngOnInit() { this.heroCache.fetchCachedHero(this.heroId); }
|
||||||
|
|
||||||
get hero() { return this._heroCache.hero; }
|
get hero() { return this.heroCache.hero; }
|
||||||
}
|
}
|
||||||
// #enddocregion component
|
// #enddocregion component
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { Hero } from './hero';
|
import { Hero } from './hero';
|
||||||
import { HeroService } from './hero.service';
|
import { HeroService } from './hero.service';
|
||||||
|
|
||||||
@ -7,11 +8,11 @@ import {HeroService} from './hero.service';
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class HeroCacheService {
|
export class HeroCacheService {
|
||||||
hero:Hero;
|
hero:Hero;
|
||||||
constructor(private _heroService:HeroService){}
|
constructor(private heroService:HeroService){}
|
||||||
|
|
||||||
fetchCachedHero(id:number){
|
fetchCachedHero(id:number){
|
||||||
if (!this.hero) {
|
if (!this.hero) {
|
||||||
this.hero = this._heroService.getHeroById(id);
|
this.hero = this.heroService.getHeroById(id);
|
||||||
}
|
}
|
||||||
return this.hero
|
return this.hero
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Component, ElementRef, Host, Inject, Optional } from '@angular/core';
|
import { Component, ElementRef, Host, Inject, Optional } from '@angular/core';
|
||||||
|
|
||||||
import { HeroCacheService } from './hero-cache.service';
|
import { HeroCacheService } from './hero-cache.service';
|
||||||
import { LoggerService } from './logger.service';
|
import { LoggerService } from './logger.service';
|
||||||
|
|
||||||
@ -18,22 +19,22 @@ export class HeroContactComponent {
|
|||||||
constructor(
|
constructor(
|
||||||
// #docregion ctor-params
|
// #docregion ctor-params
|
||||||
@Host() // limit to the host component's instance of the HeroCacheService
|
@Host() // limit to the host component's instance of the HeroCacheService
|
||||||
private _heroCache: HeroCacheService,
|
private heroCache: HeroCacheService,
|
||||||
|
|
||||||
@Host() // limit search for logger; hides the application-wide logger
|
@Host() // limit search for logger; hides the application-wide logger
|
||||||
@Optional() // ok if the logger doesn't exist
|
@Optional() // ok if the logger doesn't exist
|
||||||
private _loggerService: LoggerService
|
private loggerService: LoggerService
|
||||||
// #enddocregion ctor-params
|
// #enddocregion ctor-params
|
||||||
) {
|
) {
|
||||||
if (_loggerService) {
|
if (loggerService) {
|
||||||
this.hasLogger = true;
|
this.hasLogger = true;
|
||||||
_loggerService.logInfo('HeroContactComponent can log!');
|
loggerService.logInfo('HeroContactComponent can log!');
|
||||||
}
|
}
|
||||||
// #docregion ctor
|
// #docregion ctor
|
||||||
}
|
}
|
||||||
// #enddocregion ctor
|
// #enddocregion ctor
|
||||||
|
|
||||||
get phoneNumber() { return this._heroCache.hero.phone; }
|
get phoneNumber() { return this.heroCache.hero.phone; }
|
||||||
|
|
||||||
}
|
}
|
||||||
// #enddocregion component
|
// #enddocregion component
|
||||||
|
@ -6,17 +6,17 @@ import {Hero} from './hero';
|
|||||||
export class HeroService {
|
export class HeroService {
|
||||||
|
|
||||||
//TODO move to database
|
//TODO move to database
|
||||||
private _heroes:Array<Hero> = [
|
private heroes:Array<Hero> = [
|
||||||
new Hero(1, 'RubberMan','Hero of many talents', '123-456-7899'),
|
new Hero(1, 'RubberMan','Hero of many talents', '123-456-7899'),
|
||||||
new Hero(2, 'Magma','Hero of all trades', '555-555-5555'),
|
new Hero(2, 'Magma','Hero of all trades', '555-555-5555'),
|
||||||
new Hero(3, 'Mr. Nice','The name says it all','111-222-3333')
|
new Hero(3, 'Mr. Nice','The name says it all','111-222-3333')
|
||||||
];
|
];
|
||||||
|
|
||||||
getHeroById(id:number):Hero{
|
getHeroById(id:number):Hero{
|
||||||
return this._heroes.filter(hero => hero.id === id)[0];
|
return this.heroes.filter(hero => hero.id === id)[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
getAllHeroes():Array<Hero>{
|
getAllHeroes():Array<Hero>{
|
||||||
return this._heroes;
|
return this.heroes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,16 +13,16 @@ export class HighlightDirective {
|
|||||||
|
|
||||||
@Input('myHighlight') highlightColor: string;
|
@Input('myHighlight') highlightColor: string;
|
||||||
|
|
||||||
private _el: HTMLElement;
|
private el: HTMLElement;
|
||||||
|
|
||||||
constructor(el: ElementRef) {
|
constructor(el: ElementRef) {
|
||||||
this._el = el.nativeElement;
|
this.el = el.nativeElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
onMouseEnter() { this._highlight(this.highlightColor || 'cyan'); }
|
onMouseEnter() { this.highlight(this.highlightColor || 'cyan'); }
|
||||||
onMouseLeave() { this._highlight(null); }
|
onMouseLeave() { this.highlight(null); }
|
||||||
|
|
||||||
private _highlight(color: string) {
|
private highlight(color: string) {
|
||||||
this._el.style.backgroundColor = color;
|
this.el.style.backgroundColor = color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,7 @@
|
|||||||
import { bootstrap } from '@angular/platform-browser-dynamic';
|
import { bootstrap } from '@angular/platform-browser-dynamic';
|
||||||
import { provide } from '@angular/core';
|
import { provide } from '@angular/core';
|
||||||
import { XHRBackend } from '@angular/http';
|
import { XHRBackend } from '@angular/http';
|
||||||
|
|
||||||
import { ROUTER_PROVIDERS } from '@angular/router-deprecated';
|
import { ROUTER_PROVIDERS } from '@angular/router-deprecated';
|
||||||
|
|
||||||
import { LocationStrategy,
|
import { LocationStrategy,
|
||||||
HashLocationStrategy } from '@angular/common';
|
HashLocationStrategy } from '@angular/common';
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
import { OpaqueToken } from '@angular/core';
|
import { OpaqueToken } from '@angular/core';
|
||||||
|
|
||||||
import { Hero } from './hero';
|
import { Hero } from './hero';
|
||||||
import { HeroService } from './hero.service';
|
import { HeroService } from './hero.service';
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
|
||||||
import { Hero } from './hero';
|
import { Hero } from './hero';
|
||||||
import { HeroService } from './hero.service';
|
import { HeroService } from './hero.service';
|
||||||
|
|
||||||
@ -12,18 +13,18 @@ import {HeroService} from './hero.service';
|
|||||||
providers: [HeroService]
|
providers: [HeroService]
|
||||||
})
|
})
|
||||||
export class HeroesBaseComponent implements OnInit {
|
export class HeroesBaseComponent implements OnInit {
|
||||||
constructor(private _heroService: HeroService) { }
|
constructor(private heroService: HeroService) { }
|
||||||
// #enddocregion injection
|
// #enddocregion injection
|
||||||
|
|
||||||
heroes: Array<Hero>;
|
heroes: Array<Hero>;
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.heroes = this._heroService.getAllHeroes();
|
this.heroes = this.heroService.getAllHeroes();
|
||||||
this._afterGetHeroes();
|
this.afterGetHeroes();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Post-process heroes in derived class override.
|
// Post-process heroes in derived class override.
|
||||||
protected _afterGetHeroes() {}
|
protected afterGetHeroes() {}
|
||||||
|
|
||||||
// #docregion injection
|
// #docregion injection
|
||||||
}
|
}
|
||||||
@ -41,7 +42,7 @@ export class SortedHeroesComponent extends HeroesBaseComponent {
|
|||||||
super(heroService);
|
super(heroService);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _afterGetHeroes() {
|
protected afterGetHeroes() {
|
||||||
this.heroes = this.heroes.sort((h1, h2) => {
|
this.heroes = this.heroes.sort((h1, h2) => {
|
||||||
return h1.name < h2.name ? -1 :
|
return h1.name < h2.name ? -1 :
|
||||||
(h1.name > h2.name ? 1 : 0);
|
(h1.name > h2.name ? 1 : 0);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { LoggerService } from './logger.service';
|
import { LoggerService } from './logger.service';
|
||||||
import { UserService } from './user.service';
|
import { UserService } from './user.service';
|
||||||
|
|
||||||
@ -13,7 +14,7 @@ export class UserContextService {
|
|||||||
loggedInSince:Date;
|
loggedInSince:Date;
|
||||||
|
|
||||||
// #docregion ctor, injectables
|
// #docregion ctor, injectables
|
||||||
constructor(private _userService:UserService, private _loggerService:LoggerService){
|
constructor(private userService:UserService, private loggerService:LoggerService){
|
||||||
// #enddocregion ctor, injectables
|
// #enddocregion ctor, injectables
|
||||||
this.loggedInSince = new Date();
|
this.loggedInSince = new Date();
|
||||||
// #docregion ctor, injectables
|
// #docregion ctor, injectables
|
||||||
@ -21,11 +22,11 @@ export class UserContextService {
|
|||||||
// #enddocregion ctor, injectables
|
// #enddocregion ctor, injectables
|
||||||
|
|
||||||
loadUser(userId:number){
|
loadUser(userId:number){
|
||||||
let user = this._userService.getUserById(userId);
|
let user = this.userService.getUserById(userId);
|
||||||
this.name = user.name;
|
this.name = user.name;
|
||||||
this.role = user.role;
|
this.role = user.role;
|
||||||
|
|
||||||
this._loggerService.logDebug('loaded User');
|
this.loggerService.logDebug('loaded User');
|
||||||
}
|
}
|
||||||
// #docregion injectables, injectable
|
// #docregion injectables, injectable
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core'
|
import { Component } from '@angular/core'
|
||||||
|
|
||||||
import { DynamicForm } from './dynamic-form.component';
|
import { DynamicForm } from './dynamic-form.component';
|
||||||
import { QuestionService } from './question.service';
|
import { QuestionService } from './question.service';
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component, Input } from '@angular/core';
|
import { Component, Input } from '@angular/core';
|
||||||
import { ControlGroup } from '@angular/common';
|
import { ControlGroup } from '@angular/common';
|
||||||
|
|
||||||
import { QuestionBase } from './question-base';
|
import { QuestionBase } from './question-base';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -18,10 +18,10 @@ export class DynamicForm {
|
|||||||
form: ControlGroup;
|
form: ControlGroup;
|
||||||
payLoad = '';
|
payLoad = '';
|
||||||
|
|
||||||
constructor(private _qcs: QuestionControlService) { }
|
constructor(private qcs: QuestionControlService) { }
|
||||||
|
|
||||||
ngOnInit(){
|
ngOnInit(){
|
||||||
this.form = this._qcs.toControlGroup(this.questions);
|
this.form = this.qcs.toControlGroup(this.questions);
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { bootstrap } from '@angular/platform-browser-dynamic';
|
import { bootstrap } from '@angular/platform-browser-dynamic';
|
||||||
|
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
|
||||||
bootstrap(AppComponent, [])
|
bootstrap(AppComponent, [])
|
||||||
|
@ -5,7 +5,7 @@ import {QuestionBase} from './question-base';
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class QuestionControlService {
|
export class QuestionControlService {
|
||||||
constructor(private _fb:FormBuilder){ }
|
constructor(private fb:FormBuilder){ }
|
||||||
|
|
||||||
toControlGroup(questions:QuestionBase<any>[] ) {
|
toControlGroup(questions:QuestionBase<any>[] ) {
|
||||||
let group = {};
|
let group = {};
|
||||||
@ -13,6 +13,6 @@ export class QuestionControlService {
|
|||||||
questions.forEach(question => {
|
questions.forEach(question => {
|
||||||
group[question.key] = question.required ? [question.value || '', Validators.required] : [];
|
group[question.key] = question.required ? [question.value || '', Validators.required] : [];
|
||||||
});
|
});
|
||||||
return this._fb.group(group);
|
return this.fb.group(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { QuestionBase } from './question-base';
|
import { QuestionBase } from './question-base';
|
||||||
import { DynamicForm } from './dynamic-form.component';
|
import { DynamicForm } from './dynamic-form.component';
|
||||||
import { TextboxQuestion } from './question-textbox';
|
import { TextboxQuestion } from './question-textbox';
|
||||||
|
@ -20,10 +20,10 @@ template:
|
|||||||
})
|
})
|
||||||
// #docregion class
|
// #docregion class
|
||||||
export class AppComponent {
|
export class AppComponent {
|
||||||
public constructor(private _titleService: Title ) { }
|
public constructor(private titleService: Title ) { }
|
||||||
|
|
||||||
public setTitle( newTitle: string) {
|
public setTitle( newTitle: string) {
|
||||||
this._titleService.setTitle( newTitle );
|
this.titleService.setTitle( newTitle );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// #enddocregion class
|
// #enddocregion class
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { bootstrap } from '@angular/platform-browser-dynamic';
|
import { bootstrap } from '@angular/platform-browser-dynamic';
|
||||||
|
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
|
||||||
// While Angular supplies a Title service for setting the HTML document title
|
// While Angular supplies a Title service for setting the HTML document title
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { DataService } from './data.service';
|
import { DataService } from './data.service';
|
||||||
|
|
||||||
// #docregion
|
// #docregion
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { Component, Input } from '@angular/core';
|
import { Component, Input } from '@angular/core';
|
||||||
|
|
||||||
import { Hero } from './hero';
|
import { Hero } from './hero';
|
||||||
import { HeroDetailsComponent } from './hero-details.component';
|
import { HeroDetailsComponent } from './hero-details.component';
|
||||||
import { HeroControlsComponent } from './hero-controls.component';
|
import { HeroControlsComponent } from './hero-controls.component';
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { CarComponent } from './car/car.component';
|
import { CarComponent } from './car/car.component';
|
||||||
import { HeroesComponent } from './heroes/heroes.component.1';
|
import { HeroesComponent } from './heroes/heroes.component.1';
|
||||||
|
|
||||||
|
@ -47,15 +47,15 @@ export class AppComponent {
|
|||||||
//#docregion ctor
|
//#docregion ctor
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(APP_CONFIG) config:Config,
|
@Inject(APP_CONFIG) config:Config,
|
||||||
private _userService: UserService) {
|
private userService: UserService) {
|
||||||
|
|
||||||
this.title = config.title;
|
this.title = config.title;
|
||||||
}
|
}
|
||||||
// #enddocregion ctor
|
// #enddocregion ctor
|
||||||
|
|
||||||
get isAuthorized() { return this.user.isAuthorized;}
|
get isAuthorized() { return this.user.isAuthorized;}
|
||||||
nextUser() { this._userService.getNewUser(); }
|
nextUser() { this.userService.getNewUser(); }
|
||||||
get user() { return this._userService.user; }
|
get user() { return this.userService.user; }
|
||||||
|
|
||||||
get userInfo() {
|
get userInfo() {
|
||||||
return `Current user, ${this.user.name}, is `+
|
return `Current user, ${this.user.name}, is `+
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component, Injector } from '@angular/core';
|
import { Component, Injector } from '@angular/core';
|
||||||
|
|
||||||
import { Car, Engine, Tires } from './car';
|
import { Car, Engine, Tires } from './car';
|
||||||
import { Car as CarNoDi } from './car-no-di';
|
import { Car as CarNoDi } from './car-no-di';
|
||||||
import { CarFactory } from './car-factory';
|
import { CarFactory } from './car-factory';
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { HEROES } from './mock-heroes';
|
import { HEROES } from './mock-heroes';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { Hero } from './hero';
|
import { Hero } from './hero';
|
||||||
import { HeroService } from './hero.service';
|
import { HeroService } from './hero.service';
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { Hero } from './hero';
|
import { Hero } from './hero';
|
||||||
import { HeroService } from './hero.service';
|
import { HeroService } from './hero.service';
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { Hero } from './hero';
|
import { Hero } from './hero';
|
||||||
import { HEROES } from './mock-heroes';
|
import { HEROES } from './mock-heroes';
|
||||||
import { Logger } from '../logger.service';
|
import { Logger } from '../logger.service';
|
||||||
@ -8,11 +9,11 @@ import {Logger} from '../logger.service';
|
|||||||
export class HeroService {
|
export class HeroService {
|
||||||
|
|
||||||
//#docregion ctor
|
//#docregion ctor
|
||||||
constructor(private _logger: Logger) { }
|
constructor(private logger: Logger) { }
|
||||||
//#enddocregion ctor
|
//#enddocregion ctor
|
||||||
|
|
||||||
getHeroes() {
|
getHeroes() {
|
||||||
this._logger.log('Getting heroes ...')
|
this.logger.log('Getting heroes ...')
|
||||||
return HEROES;
|
return HEROES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { provide } from '@angular/core';
|
import { provide } from '@angular/core';
|
||||||
|
|
||||||
import { HeroService } from './hero.service';
|
import { HeroService } from './hero.service';
|
||||||
import { Logger } from '../logger.service';
|
import { Logger } from '../logger.service';
|
||||||
import { UserService } from '../user.service';
|
import { UserService } from '../user.service';
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { Hero } from './hero';
|
import { Hero } from './hero';
|
||||||
import { HEROES } from './mock-heroes';
|
import { HEROES } from './mock-heroes';
|
||||||
import { Logger } from '../logger.service';
|
import { Logger } from '../logger.service';
|
||||||
@ -10,13 +11,13 @@ export class HeroService {
|
|||||||
|
|
||||||
// #docregion internals
|
// #docregion internals
|
||||||
constructor(
|
constructor(
|
||||||
private _logger: Logger,
|
private logger: Logger,
|
||||||
private _isAuthorized: boolean) { }
|
private isAuthorized: boolean) { }
|
||||||
|
|
||||||
getHeroes() {
|
getHeroes() {
|
||||||
let auth = this._isAuthorized ? 'authorized ': 'unauthorized';
|
let auth = this.isAuthorized ? 'authorized ': 'unauthorized';
|
||||||
this._logger.log(`Getting heroes for ${auth} user.`);
|
this.logger.log(`Getting heroes for ${auth} user.`);
|
||||||
return HEROES.filter(hero => this._isAuthorized || !hero.isSecret);
|
return HEROES.filter(hero => this.isAuthorized || !hero.isSecret);
|
||||||
}
|
}
|
||||||
// #enddocregion internals
|
// #enddocregion internals
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
// #docregion v1
|
// #docregion v1
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { HeroListComponent } from './hero-list.component';
|
import { HeroListComponent } from './hero-list.component';
|
||||||
// #enddocregion v1
|
// #enddocregion v1
|
||||||
import { HeroService } from './hero.service';
|
import { HeroService } from './hero.service';
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { HeroListComponent } from './hero-list.component';
|
import { HeroListComponent } from './hero-list.component';
|
||||||
import { heroServiceProvider} from './hero.service.provider';
|
import { heroServiceProvider} from './hero.service.provider';
|
||||||
|
|
||||||
|
@ -16,21 +16,22 @@ import {Logger} from './logger.service';
|
|||||||
<div id="hero">{{hero.name}}</div>
|
<div id="hero">{{hero.name}}</div>
|
||||||
<div id="rodent">{{rodent}}</div>
|
<div id="rodent">{{rodent}}</div>
|
||||||
`,
|
`,
|
||||||
|
|
||||||
providers: [Car, Engine, Tires,
|
providers: [Car, Engine, Tires,
|
||||||
heroServiceProvider, Logger]
|
heroServiceProvider, Logger]
|
||||||
})
|
})
|
||||||
export class InjectorComponent {
|
export class InjectorComponent {
|
||||||
constructor(private _injector: Injector) { }
|
constructor(private injector: Injector) { }
|
||||||
|
|
||||||
car:Car = this._injector.get(Car);
|
car:Car = this.injector.get(Car);
|
||||||
|
|
||||||
//#docregion get-hero-service
|
//#docregion get-hero-service
|
||||||
heroService:HeroService = this._injector.get(HeroService);
|
heroService:HeroService = this.injector.get(HeroService);
|
||||||
//#enddocregion get-hero-service
|
//#enddocregion get-hero-service
|
||||||
hero = this.heroService.getHeroes()[0];
|
hero = this.heroService.getHeroes()[0];
|
||||||
|
|
||||||
get rodent() {
|
get rodent() {
|
||||||
let rous = this._injector.get(ROUS, null);
|
let rous = this.injector.get(ROUS, null);
|
||||||
if (rous) {
|
if (rous) {
|
||||||
throw new Error('Aaaargh!')
|
throw new Error('Aaaargh!')
|
||||||
}
|
}
|
||||||
|
@ -89,10 +89,10 @@ export class ProviderComponent4 {
|
|||||||
class EvenBetterLogger {
|
class EvenBetterLogger {
|
||||||
logs:string[] = [];
|
logs:string[] = [];
|
||||||
|
|
||||||
constructor(private _userService: UserService) { }
|
constructor(private userService: UserService) { }
|
||||||
|
|
||||||
log(message:string){
|
log(message:string){
|
||||||
message = `Message to ${this._userService.user.name}: ${message}.`;
|
message = `Message to ${this.userService.user.name}: ${message}.`;
|
||||||
console.log(message);
|
console.log(message);
|
||||||
this.logs.push(message);
|
this.logs.push(message);
|
||||||
}
|
}
|
||||||
@ -230,17 +230,17 @@ export class ProviderComponent9a {
|
|||||||
/*
|
/*
|
||||||
// #docregion provider-9a-ctor-interface
|
// #docregion provider-9a-ctor-interface
|
||||||
// FAIL! Can't inject using the interface as the parameter type
|
// FAIL! Can't inject using the interface as the parameter type
|
||||||
constructor(private _config: Config){ }
|
constructor(private config: Config){ }
|
||||||
// #enddocregion provider-9a-ctor-interface
|
// #enddocregion provider-9a-ctor-interface
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// #docregion provider-9a-ctor
|
// #docregion provider-9a-ctor
|
||||||
// @Inject(token) to inject the dependency
|
// @Inject(token) to inject the dependency
|
||||||
constructor(@Inject('app.config') private _config: Config){ }
|
constructor(@Inject('app.config') private config: Config){ }
|
||||||
// #enddocregion provider-9a-ctor
|
// #enddocregion provider-9a-ctor
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.log = '"app.config" Application title is ' + this._config.title;
|
this.log = '"app.config" Application title is ' + this.config.title;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,11 +254,11 @@ export class ProviderComponent9a {
|
|||||||
export class ProviderComponent9b {
|
export class ProviderComponent9b {
|
||||||
log: string;
|
log: string;
|
||||||
// #docregion provider-9b-ctor
|
// #docregion provider-9b-ctor
|
||||||
constructor(@Inject(APP_CONFIG) private _config: Config){ }
|
constructor(@Inject(APP_CONFIG) private config: Config){ }
|
||||||
// #enddocregion provider-9b-ctor
|
// #enddocregion provider-9b-ctor
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.log = 'APP_CONFIG Application title is ' + this._config.title;
|
this.log = 'APP_CONFIG Application title is ' + this.config.title;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//////////////////////////////////////////
|
//////////////////////////////////////////
|
||||||
@ -290,27 +290,27 @@ import {Optional} from '@angular/core';
|
|||||||
export class ProviderComponent10b {
|
export class ProviderComponent10b {
|
||||||
// #docregion provider-10-ctor
|
// #docregion provider-10-ctor
|
||||||
log:string;
|
log:string;
|
||||||
constructor(@Optional() private _logger:Logger) { }
|
constructor(@Optional() private logger:Logger) { }
|
||||||
// #enddocregion provider-10-ctor
|
// #enddocregion provider-10-ctor
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
// #docregion provider-10-logger
|
// #docregion provider-10-logger
|
||||||
// No logger? Make one!
|
// No logger? Make one!
|
||||||
if (!this._logger) {
|
if (!this.logger) {
|
||||||
this._logger = {
|
this.logger = {
|
||||||
log: (msg:string)=> this._logger.logs.push(msg),
|
log: (msg:string)=> this.logger.logs.push(msg),
|
||||||
logs: []
|
logs: []
|
||||||
}
|
}
|
||||||
// #enddocregion provider-10-logger
|
// #enddocregion provider-10-logger
|
||||||
this._logger.log("Optional logger was not available.")
|
this.logger.log("Optional logger was not available.")
|
||||||
// #docregion provider-10-logger
|
// #docregion provider-10-logger
|
||||||
}
|
}
|
||||||
// #enddocregion provider-10-logger
|
// #enddocregion provider-10-logger
|
||||||
else {
|
else {
|
||||||
this._logger.log('Hello from the injected logger.')
|
this.logger.log('Hello from the injected logger.')
|
||||||
this.log = this._logger.logs[0];
|
this.log = this.logger.logs[0];
|
||||||
}
|
}
|
||||||
this.log = this._logger.logs[0];
|
this.log = this.logger.logs[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// Reader should look to the testing chapter for the real thing
|
// Reader should look to the testing chapter for the real thing
|
||||||
|
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { HeroService } from './heroes/hero.service';
|
import { HeroService } from './heroes/hero.service';
|
||||||
import { HeroListComponent } from './heroes/hero-list.component';
|
import { HeroListComponent } from './heroes/hero-list.component';
|
||||||
|
|
||||||
|
@ -17,7 +17,8 @@ import {Hero} from './hero';
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
// #docregion message
|
// #docregion message
|
||||||
<p *ngIf="heroes.length > 3">There are many heroes!</p>
|
<p *ngIf="heroes.length
|
||||||
|
> 3">There are many heroes!</p>
|
||||||
// #enddocregion message
|
// #enddocregion message
|
||||||
`
|
`
|
||||||
})
|
})
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { bootstrap } from '@angular/platform-browser-dynamic';
|
import { bootstrap } from '@angular/platform-browser-dynamic';
|
||||||
|
|
||||||
import { AppCtorComponent } from './app-ctor.component';
|
import { AppCtorComponent } from './app-ctor.component';
|
||||||
import { AppComponent as v1 } from './app.component.1';
|
import { AppComponent as v1 } from './app.component.1';
|
||||||
import { AppComponent as v2 } from './app.component.2';
|
import { AppComponent as v2 } from './app.component.2';
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { bootstrap } from '@angular/platform-browser-dynamic';
|
import { bootstrap } from '@angular/platform-browser-dynamic';
|
||||||
|
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
|
||||||
bootstrap(AppComponent);
|
bootstrap(AppComponent);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
// #docregion first, final
|
// #docregion first, final
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { NgForm } from '@angular/common';
|
import { NgForm } from '@angular/common';
|
||||||
|
|
||||||
import { Hero } from './hero';
|
import { Hero } from './hero';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { bootstrap } from '@angular/platform-browser-dynamic';
|
import { bootstrap } from '@angular/platform-browser-dynamic';
|
||||||
|
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
|
||||||
bootstrap(AppComponent);
|
bootstrap(AppComponent);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component, Input } from '@angular/core';
|
import { Component, Input } from '@angular/core';
|
||||||
|
|
||||||
import { Hero } from './hero';
|
import { Hero } from './hero';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import {Component, Input, Output, EventEmitter} from '@angular/core';
|
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
||||||
|
|
||||||
import { RestoreService } from './restore.service';
|
import { RestoreService } from './restore.service';
|
||||||
import { Hero } from './hero';
|
import { Hero } from './hero';
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { EditItem } from './edit-item';
|
import { EditItem } from './edit-item';
|
||||||
import { HeroesService } from './heroes.service';
|
import { HeroesService } from './heroes.service';
|
||||||
import { HeroCardComponent } from './hero-card.component';
|
import { HeroCardComponent } from './hero-card.component';
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { bootstrap } from '@angular/platform-browser-dynamic';
|
import { bootstrap } from '@angular/platform-browser-dynamic';
|
||||||
|
|
||||||
import { HeroesListComponent } from './heroes-list.component';
|
import { HeroesListComponent } from './heroes-list.component';
|
||||||
import { HeroesService } from './heroes.service';
|
import { HeroesService } from './heroes.service';
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { bootstrap } from '@angular/platform-browser-dynamic';
|
import { bootstrap } from '@angular/platform-browser-dynamic';
|
||||||
|
|
||||||
import { HelloWorld } from './hello_world';
|
import { HelloWorld } from './hello_world';
|
||||||
|
|
||||||
bootstrap(HelloWorld);
|
bootstrap(HelloWorld);
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { UiTabs, UiPane } from './ui_tabs';
|
import { UiTabs, UiPane } from './ui_tabs';
|
||||||
|
|
||||||
class Detail {
|
class Detail {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { bootstrap } from '@angular/platform-browser-dynamic';
|
import { bootstrap } from '@angular/platform-browser-dynamic';
|
||||||
|
|
||||||
import { DiDemo } from './di_demo';
|
import { DiDemo } from './di_demo';
|
||||||
|
|
||||||
bootstrap(DiDemo);
|
bootstrap(DiDemo);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { bootstrap } from '@angular/platform-browser-dynamic';
|
import { bootstrap } from '@angular/platform-browser-dynamic';
|
||||||
|
|
||||||
import { TodoApp } from './todo_app';
|
import { TodoApp } from './todo_app';
|
||||||
|
|
||||||
bootstrap(TodoApp);
|
bootstrap(TodoApp);
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { Todo } from './todo';
|
import { Todo } from './todo';
|
||||||
import { TodoList } from './todo_list';
|
import { TodoList } from './todo_list';
|
||||||
import { TodoForm } from './todo_form';
|
import { TodoForm } from './todo_form';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Component, AfterContentChecked, AfterContentInit, ContentChild} from '@angular/core';
|
import { AfterContentChecked, AfterContentInit, Component, ContentChild } from '@angular/core';
|
||||||
|
|
||||||
import {LoggerService} from './logger.service';
|
import {LoggerService} from './logger.service';
|
||||||
|
|
||||||
@ -30,32 +30,32 @@ export class ChildComponent {
|
|||||||
})
|
})
|
||||||
// #docregion hooks
|
// #docregion hooks
|
||||||
export class AfterContentComponent implements AfterContentChecked, AfterContentInit {
|
export class AfterContentComponent implements AfterContentChecked, AfterContentInit {
|
||||||
private _prevHero = '';
|
private prevHero = '';
|
||||||
comment = '';
|
comment = '';
|
||||||
|
|
||||||
// Query for a CONTENT child of type `ChildComponent`
|
// Query for a CONTENT child of type `ChildComponent`
|
||||||
@ContentChild(ChildComponent) contentChild: ChildComponent;
|
@ContentChild(ChildComponent) contentChild: ChildComponent;
|
||||||
|
|
||||||
// #enddocregion hooks
|
// #enddocregion hooks
|
||||||
constructor(private _logger: LoggerService) {
|
constructor(private logger: LoggerService) {
|
||||||
this._logIt('AfterContent constructor');
|
this.logIt('AfterContent constructor');
|
||||||
}
|
}
|
||||||
|
|
||||||
// #docregion hooks
|
// #docregion hooks
|
||||||
ngAfterContentInit() {
|
ngAfterContentInit() {
|
||||||
// viewChild is set after the view has been initialized
|
// viewChild is set after the view has been initialized
|
||||||
this._logIt('AfterContentInit');
|
this.logIt('AfterContentInit');
|
||||||
this._doSomething();
|
this.doSomething();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterContentChecked() {
|
ngAfterContentChecked() {
|
||||||
// viewChild is updated after the view has been checked
|
// viewChild is updated after the view has been checked
|
||||||
if (this._prevHero === this.contentChild.hero) {
|
if (this.prevHero === this.contentChild.hero) {
|
||||||
this._logIt('AfterContentChecked (no change)');
|
this.logIt('AfterContentChecked (no change)');
|
||||||
} else {
|
} else {
|
||||||
this._prevHero = this.contentChild.hero;
|
this.prevHero = this.contentChild.hero;
|
||||||
this._logIt('AfterContentChecked');
|
this.logIt('AfterContentChecked');
|
||||||
this._doSomething();
|
this.doSomething();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// #enddocregion hooks
|
// #enddocregion hooks
|
||||||
@ -64,14 +64,14 @@ export class AfterContentComponent implements AfterContentChecked, AfterContent
|
|||||||
// #docregion do-something
|
// #docregion do-something
|
||||||
|
|
||||||
// This surrogate for real business logic sets the `comment`
|
// This surrogate for real business logic sets the `comment`
|
||||||
private _doSomething() {
|
private doSomething() {
|
||||||
this.comment = this.contentChild.hero.length > 10 ? 'That\'s a long name' : '';
|
this.comment = this.contentChild.hero.length > 10 ? 'That\'s a long name' : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
private _logIt(method: string) {
|
private logIt(method: string) {
|
||||||
let vc = this.contentChild;
|
let vc = this.contentChild;
|
||||||
let message = `${method}: ${vc ? vc.hero : 'no'} child view`;
|
let message = `${method}: ${vc ? vc.hero : 'no'} child view`;
|
||||||
this._logger.log(message);
|
this.logger.log(message);
|
||||||
}
|
}
|
||||||
// #docregion hooks
|
// #docregion hooks
|
||||||
// ...
|
// ...
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Component, AfterViewChecked, AfterViewInit, ViewChild} from '@angular/core';
|
import { AfterViewChecked, AfterViewInit, Component, ViewChild } from '@angular/core';
|
||||||
|
|
||||||
import {LoggerService} from './logger.service';
|
import {LoggerService} from './logger.service';
|
||||||
|
|
||||||
@ -34,31 +34,31 @@ export class ChildViewComponent {
|
|||||||
})
|
})
|
||||||
// #docregion hooks
|
// #docregion hooks
|
||||||
export class AfterViewComponent implements AfterViewChecked, AfterViewInit {
|
export class AfterViewComponent implements AfterViewChecked, AfterViewInit {
|
||||||
private _prevHero = '';
|
private prevHero = '';
|
||||||
|
|
||||||
// Query for a VIEW child of type `ChildViewComponent`
|
// Query for a VIEW child of type `ChildViewComponent`
|
||||||
@ViewChild(ChildViewComponent) viewChild: ChildViewComponent;
|
@ViewChild(ChildViewComponent) viewChild: ChildViewComponent;
|
||||||
|
|
||||||
// #enddocregion hooks
|
// #enddocregion hooks
|
||||||
constructor(private _logger:LoggerService){
|
constructor(private logger:LoggerService){
|
||||||
this._logIt('AfterView constructor');
|
this.logIt('AfterView constructor');
|
||||||
}
|
}
|
||||||
|
|
||||||
// #docregion hooks
|
// #docregion hooks
|
||||||
ngAfterViewInit() {
|
ngAfterViewInit() {
|
||||||
// viewChild is set after the view has been initialized
|
// viewChild is set after the view has been initialized
|
||||||
this._logIt('AfterViewInit');
|
this.logIt('AfterViewInit');
|
||||||
this._doSomething();
|
this.doSomething();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewChecked() {
|
ngAfterViewChecked() {
|
||||||
// viewChild is updated after the view has been checked
|
// viewChild is updated after the view has been checked
|
||||||
if (this._prevHero === this.viewChild.hero) {
|
if (this.prevHero === this.viewChild.hero) {
|
||||||
this._logIt('AfterViewChecked (no change)');
|
this.logIt('AfterViewChecked (no change)');
|
||||||
} else {
|
} else {
|
||||||
this._prevHero = this.viewChild.hero;
|
this.prevHero = this.viewChild.hero;
|
||||||
this._logIt('AfterViewChecked');
|
this.logIt('AfterViewChecked');
|
||||||
this._doSomething();
|
this.doSomething();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// #enddocregion hooks
|
// #enddocregion hooks
|
||||||
@ -67,7 +67,7 @@ export class AfterViewComponent implements AfterViewChecked, AfterViewInit {
|
|||||||
|
|
||||||
// #docregion do-something
|
// #docregion do-something
|
||||||
// This surrogate for real business logic sets the `comment`
|
// This surrogate for real business logic sets the `comment`
|
||||||
private _doSomething() {
|
private doSomething() {
|
||||||
let c = this.viewChild.hero.length > 10 ? "That's a long name" : '';
|
let c = this.viewChild.hero.length > 10 ? "That's a long name" : '';
|
||||||
if (c !== this.comment) {
|
if (c !== this.comment) {
|
||||||
// Wait a tick because the component's view has already been checked
|
// Wait a tick because the component's view has already been checked
|
||||||
@ -76,10 +76,10 @@ export class AfterViewComponent implements AfterViewChecked, AfterViewInit {
|
|||||||
}
|
}
|
||||||
// #enddocregion do-something
|
// #enddocregion do-something
|
||||||
|
|
||||||
private _logIt(method:string){
|
private logIt(method:string){
|
||||||
let vc = this.viewChild;
|
let vc = this.viewChild;
|
||||||
let message = `${method}: ${vc ? vc.hero:'no'} child view`
|
let message = `${method}: ${vc ? vc.hero:'no'} child view`
|
||||||
this._logger.log(message);
|
this.logger.log(message);
|
||||||
}
|
}
|
||||||
// #docregion hooks
|
// #docregion hooks
|
||||||
// ...
|
// ...
|
||||||
|
@ -66,23 +66,23 @@ export class CounterParentComponent {
|
|||||||
value: number;
|
value: number;
|
||||||
spyLog: string[] = [];
|
spyLog: string[] = [];
|
||||||
|
|
||||||
private _logger: LoggerService;
|
private logger: LoggerService;
|
||||||
|
|
||||||
constructor(logger: LoggerService) {
|
constructor(logger: LoggerService) {
|
||||||
this._logger = logger;
|
this.logger = logger;
|
||||||
this.spyLog = logger.logs;
|
this.spyLog = logger.logs;
|
||||||
this.reset();
|
this.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCounter() {
|
updateCounter() {
|
||||||
this.value += 1;
|
this.value += 1;
|
||||||
this._logger.tick();
|
this.logger.tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
this._logger.log('-- reset --');
|
this.logger.log('-- reset --');
|
||||||
this.value = 0;
|
this.value = 0;
|
||||||
this._logger.tick();
|
this.logger.tick();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* tslint:disable:forin */
|
/* tslint:disable:forin */
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Component, DoCheck, OnChanges, Input, SimpleChange, ViewChild} from '@angular/core';
|
import { Component, DoCheck, Input, OnChanges, SimpleChange, ViewChild } from '@angular/core';
|
||||||
|
|
||||||
class Hero {
|
class Hero {
|
||||||
constructor(public name: string) {}
|
constructor(public name: string) {}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { bootstrap } from '@angular/platform-browser-dynamic';
|
import { bootstrap } from '@angular/platform-browser-dynamic';
|
||||||
|
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
|
||||||
bootstrap(AppComponent).catch(err => console.error(err));
|
bootstrap(AppComponent).catch(err => console.error(err));
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/* tslint:disable:forin */
|
/* tslint:disable:forin */
|
||||||
// #docregion
|
// #docregion
|
||||||
import {
|
import {
|
||||||
Component, Input, ViewChild,
|
Component, Input, Onchanges,
|
||||||
OnChanges, SimpleChange
|
SimpleChange, ViewChild
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { PeekABooComponent } from './peek-a-boo.component';
|
import { PeekABooComponent } from './peek-a-boo.component';
|
||||||
import { LoggerService } from './logger.service';
|
import { LoggerService } from './logger.service';
|
||||||
|
|
||||||
@ -31,10 +32,10 @@ export class PeekABooParentComponent {
|
|||||||
hookLog: string[];
|
hookLog: string[];
|
||||||
|
|
||||||
heroName = 'Windstorm';
|
heroName = 'Windstorm';
|
||||||
private _logger: LoggerService;
|
private logger: LoggerService;
|
||||||
|
|
||||||
constructor(logger: LoggerService) {
|
constructor(logger: LoggerService) {
|
||||||
this._logger = logger;
|
this.logger = logger;
|
||||||
this.hookLog = logger.logs;
|
this.hookLog = logger.logs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,13 +43,13 @@ export class PeekABooParentComponent {
|
|||||||
this.hasChild = !this.hasChild;
|
this.hasChild = !this.hasChild;
|
||||||
if (this.hasChild) {
|
if (this.hasChild) {
|
||||||
this.heroName = 'Windstorm';
|
this.heroName = 'Windstorm';
|
||||||
this._logger.clear(); // clear log on create
|
this.logger.clear(); // clear log on create
|
||||||
}
|
}
|
||||||
this._logger.tick();
|
this.logger.tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateHero() {
|
updateHero() {
|
||||||
this.heroName += '!';
|
this.heroName += '!';
|
||||||
this._logger.tick();
|
this.logger.tick();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
import {
|
import {
|
||||||
OnChanges, SimpleChange,
|
|
||||||
OnInit,
|
|
||||||
DoCheck,
|
|
||||||
AfterContentInit,
|
|
||||||
AfterContentChecked,
|
AfterContentChecked,
|
||||||
AfterViewInit,
|
AfterContentInit,
|
||||||
AfterViewChecked,
|
AfterViewChecked,
|
||||||
OnDestroy
|
AfterViewInit,
|
||||||
|
DoCheck,
|
||||||
|
OnChanges,
|
||||||
|
OnDestroy,
|
||||||
|
OnInit,
|
||||||
|
SimpleChange
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import {Component, Input} from '@angular/core';
|
import {Component, Input} from '@angular/core';
|
||||||
import {LoggerService} from './logger.service';
|
import {LoggerService} from './logger.service';
|
||||||
@ -15,13 +16,13 @@ let nextId = 1;
|
|||||||
|
|
||||||
// #docregion ngOnInit
|
// #docregion ngOnInit
|
||||||
export class PeekABoo implements OnInit {
|
export class PeekABoo implements OnInit {
|
||||||
constructor(private _logger: LoggerService) { }
|
constructor(private logger: LoggerService) { }
|
||||||
|
|
||||||
// implement OnInit's `ngOnInit` method
|
// implement OnInit's `ngOnInit` method
|
||||||
ngOnInit() { this._logIt(`OnInit`); }
|
ngOnInit() { this.logIt(`OnInit`); }
|
||||||
|
|
||||||
protected _logIt(msg: string) {
|
protected logIt(msg: string) {
|
||||||
this._logger.log(`#${nextId++} ${msg}`);
|
this.logger.log(`#${nextId++} ${msg}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// #enddocregion ngOnInit
|
// #enddocregion ngOnInit
|
||||||
@ -40,13 +41,13 @@ export class PeekABooComponent extends PeekABoo implements
|
|||||||
OnDestroy {
|
OnDestroy {
|
||||||
@Input() name: string;
|
@Input() name: string;
|
||||||
|
|
||||||
private _verb = 'initialized';
|
private verb = 'initialized';
|
||||||
|
|
||||||
constructor(logger: LoggerService) {
|
constructor(logger: LoggerService) {
|
||||||
super(logger);
|
super(logger);
|
||||||
|
|
||||||
let is = this.name ? 'is' : 'is not';
|
let is = this.name ? 'is' : 'is not';
|
||||||
this._logIt(`name ${is} known at construction`);
|
this.logIt(`name ${is} known at construction`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// only called for/if there is an @input variable set by parent.
|
// only called for/if there is an @input variable set by parent.
|
||||||
@ -55,30 +56,30 @@ export class PeekABooComponent extends PeekABoo implements
|
|||||||
for (let propName in changes) {
|
for (let propName in changes) {
|
||||||
if (propName === 'name') {
|
if (propName === 'name') {
|
||||||
let name = changes['name'].currentValue;
|
let name = changes['name'].currentValue;
|
||||||
changesMsgs.push(`name ${this._verb} to "${name}"`);
|
changesMsgs.push(`name ${this.verb} to "${name}"`);
|
||||||
} else {
|
} else {
|
||||||
changesMsgs.push(propName + ' ' + this._verb);
|
changesMsgs.push(propName + ' ' + this.verb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._logIt(`OnChanges: ${changesMsgs.join('; ')}`);
|
this.logIt(`OnChanges: ${changesMsgs.join('; ')}`);
|
||||||
this._verb = 'changed'; // next time it will be a change
|
this.verb = 'changed'; // next time it will be a change
|
||||||
}
|
}
|
||||||
|
|
||||||
// Beware! Called frequently!
|
// Beware! Called frequently!
|
||||||
// Called in every change detection cycle anywhere on the page
|
// Called in every change detection cycle anywhere on the page
|
||||||
ngDoCheck() { this._logIt(`DoCheck`); }
|
ngDoCheck() { this.logIt(`DoCheck`); }
|
||||||
|
|
||||||
ngAfterContentInit() { this._logIt(`AfterContentInit`); }
|
ngAfterContentInit() { this.logIt(`AfterContentInit`); }
|
||||||
|
|
||||||
// Beware! Called frequently!
|
// Beware! Called frequently!
|
||||||
// Called in every change detection cycle anywhere on the page
|
// Called in every change detection cycle anywhere on the page
|
||||||
ngAfterContentChecked() { this._logIt(`AfterContentChecked`); }
|
ngAfterContentChecked() { this.logIt(`AfterContentChecked`); }
|
||||||
|
|
||||||
ngAfterViewInit() { this._logIt(`AfterViewInit`); }
|
ngAfterViewInit() { this.logIt(`AfterViewInit`); }
|
||||||
|
|
||||||
// Beware! Called frequently!
|
// Beware! Called frequently!
|
||||||
// Called in every change detection cycle anywhere on the page
|
// Called in every change detection cycle anywhere on the page
|
||||||
ngAfterViewChecked() { this._logIt(`AfterViewChecked`); }
|
ngAfterViewChecked() { this.logIt(`AfterViewChecked`); }
|
||||||
|
|
||||||
ngOnDestroy() { this._logIt(`OnDestroy`); }
|
ngOnDestroy() { this.logIt(`OnDestroy`); }
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { LoggerService } from './logger.service';
|
import { LoggerService } from './logger.service';
|
||||||
import { Spy } from './spy.directive';
|
import { Spy } from './spy.directive';
|
||||||
|
|
||||||
@ -36,24 +37,24 @@ export class SpyParentComponent {
|
|||||||
heroes: string[] = ['Windstorm', 'Magneta'];
|
heroes: string[] = ['Windstorm', 'Magneta'];
|
||||||
spyLog: string[];
|
spyLog: string[];
|
||||||
|
|
||||||
constructor(private _logger: LoggerService) {
|
constructor(private logger: LoggerService) {
|
||||||
this.spyLog = _logger.logs;
|
this.spyLog = logger.logs;
|
||||||
}
|
}
|
||||||
|
|
||||||
addHero() {
|
addHero() {
|
||||||
if (this.newName.trim()) {
|
if (this.newName.trim()) {
|
||||||
this.heroes.push(this.newName.trim());
|
this.heroes.push(this.newName.trim());
|
||||||
this.newName = '';
|
this.newName = '';
|
||||||
this._logger.tick();
|
this.logger.tick();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
removeHero(hero: string) {
|
removeHero(hero: string) {
|
||||||
this.heroes.splice(this.heroes.indexOf(hero), 1);
|
this.heroes.splice(this.heroes.indexOf(hero), 1);
|
||||||
this._logger.tick();
|
this.logger.tick();
|
||||||
}
|
}
|
||||||
reset() {
|
reset() {
|
||||||
this._logger.log('-- reset --');
|
this.logger.log('-- reset --');
|
||||||
this.heroes.length = 0;
|
this.heroes.length = 0;
|
||||||
this._logger.tick();
|
this.logger.tick();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import {Directive, OnInit, OnDestroy} from '@angular/core';
|
import {Directive, OnInit, OnDestroy} from '@angular/core';
|
||||||
|
|
||||||
import {LoggerService} from './logger.service';
|
import {LoggerService} from './logger.service';
|
||||||
|
|
||||||
let nextId = 1;
|
let nextId = 1;
|
||||||
@ -10,14 +11,14 @@ let nextId = 1;
|
|||||||
@Directive({selector: '[mySpy]'})
|
@Directive({selector: '[mySpy]'})
|
||||||
export class Spy implements OnInit, OnDestroy {
|
export class Spy implements OnInit, OnDestroy {
|
||||||
|
|
||||||
constructor(private _logger: LoggerService) { }
|
constructor(private logger: LoggerService) { }
|
||||||
|
|
||||||
ngOnInit() { this._logIt(`onInit`); }
|
ngOnInit() { this.logIt(`onInit`); }
|
||||||
|
|
||||||
ngOnDestroy() { this._logIt(`onDestroy`); }
|
ngOnDestroy() { this.logIt(`onDestroy`); }
|
||||||
|
|
||||||
private _logIt(msg: string) {
|
private logIt(msg: string) {
|
||||||
this._logger.log(`Spy #${nextId++} ${msg}`);
|
this.logger.log(`Spy #${nextId++} ${msg}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// #enddocregion spy-directive
|
// #enddocregion spy-directive
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { FlyingHeroesPipe,
|
import { FlyingHeroesPipe,
|
||||||
FlyingHeroesImpurePipe } from './flying-heroes.pipe';
|
FlyingHeroesImpurePipe } from './flying-heroes.pipe';
|
||||||
import { HEROES } from './heroes';
|
import { HEROES } from './heroes';
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
// #docregion pure
|
// #docregion pure
|
||||||
import {Flyer} from './heroes';
|
|
||||||
import { Pipe, PipeTransform } from '@angular/core';
|
import { Pipe, PipeTransform } from '@angular/core';
|
||||||
|
|
||||||
|
import { Flyer } from './heroes';
|
||||||
|
|
||||||
@Pipe({ name: 'flyingHeroes' })
|
@Pipe({ name: 'flyingHeroes' })
|
||||||
export class FlyingHeroesPipe implements PipeTransform {
|
export class FlyingHeroesPipe implements PipeTransform {
|
||||||
transform(allHeroes:Flyer[]) {
|
transform(allHeroes:Flyer[]) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { FetchJsonPipe } from './fetch-json.pipe';
|
import { FetchJsonPipe } from './fetch-json.pipe';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { ExponentialStrengthPipe } from './exponential-strength.pipe';
|
import { ExponentialStrengthPipe } from './exponential-strength.pipe';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { ExponentialStrengthPipe } from './exponential-strength.pipe';
|
import { ExponentialStrengthPipe } from './exponential-strength.pipe';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { bootstrap } from '@angular/platform-browser-dynamic';
|
import { bootstrap } from '@angular/platform-browser-dynamic';
|
||||||
|
|
||||||
// #docregion app-component
|
// #docregion app-component
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
// #enddocregion app-component
|
// #enddocregion app-component
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
import { CanDeactivate, ComponentInstruction, Router } from '@angular/router-deprecated';
|
||||||
|
|
||||||
import { Crisis, CrisisService } from './crisis.service';
|
import { Crisis, CrisisService } from './crisis.service';
|
||||||
import { DialogService } from '../dialog.service';
|
import { DialogService } from '../dialog.service';
|
||||||
import {CanDeactivate, ComponentInstruction, Router} from '@angular/router-deprecated';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
template: `
|
template: `
|
||||||
@ -19,23 +20,23 @@ export class AddCrisisComponent implements CanDeactivate {
|
|||||||
editName: string;
|
editName: string;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private _service: CrisisService,
|
private service: CrisisService,
|
||||||
private _router: Router,
|
private router: Router,
|
||||||
private _dialog: DialogService) { }
|
private dialog: DialogService) { }
|
||||||
|
|
||||||
routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||||
return !!this.editName.trim() ||
|
return !!this.editName.trim() ||
|
||||||
this._dialog.confirm('Discard changes?');
|
this.dialog.confirm('Discard changes?');
|
||||||
}
|
}
|
||||||
|
|
||||||
cancel() { this.gotoCrises(); }
|
cancel() { this.gotoCrises(); }
|
||||||
|
|
||||||
save() {
|
save() {
|
||||||
this._service.addCrisis(this.editName);
|
this.service.addCrisis(this.editName);
|
||||||
this.gotoCrises();
|
this.gotoCrises();
|
||||||
}
|
}
|
||||||
|
|
||||||
gotoCrises() {
|
gotoCrises() {
|
||||||
this._router.navigate(['CrisisCenter']);
|
this.router.navigate(['CrisisCenter']);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { Routes, ROUTER_DIRECTIVES } from '@angular/router';
|
import { ROUTER_DIRECTIVES, Routes } from '@angular/router';
|
||||||
|
|
||||||
import { CrisisListComponent } from './crisis-list.component';
|
import { CrisisListComponent } from './crisis-list.component';
|
||||||
import { HeroListComponent } from './hero-list.component';
|
import { HeroListComponent } from './hero-list.component';
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { Routes, ROUTER_DIRECTIVES, Router } from '@angular/router';
|
import { Router, ROUTER_DIRECTIVES, Routes } from '@angular/router';
|
||||||
|
|
||||||
import { CrisisListComponent } from './crisis-list.component';
|
import { CrisisListComponent } from './crisis-list.component';
|
||||||
// #enddocregion
|
// #enddocregion
|
||||||
@ -11,15 +11,15 @@ import { CrisisListComponent } from './crisis-list.component';
|
|||||||
// Apparent Milestone 2 imports
|
// Apparent Milestone 2 imports
|
||||||
// #docregion
|
// #docregion
|
||||||
// #docregion hero-import
|
// #docregion hero-import
|
||||||
import { HeroListComponent } from './heroes/hero-list.component';
|
|
||||||
import { HeroDetailComponent } from './heroes/hero-detail.component';
|
import { HeroDetailComponent } from './heroes/hero-detail.component';
|
||||||
|
import { HeroListComponent } from './heroes/hero-list.component';
|
||||||
import { HeroService } from './heroes/hero.service';
|
import { HeroService } from './heroes/hero.service';
|
||||||
// #enddocregion hero-import
|
// #enddocregion hero-import
|
||||||
// #enddocregion
|
// #enddocregion
|
||||||
*/
|
*/
|
||||||
// Actual Milestone 2 imports
|
// Actual Milestone 2 imports
|
||||||
import { HeroListComponent } from './heroes/hero-list.component.1';
|
|
||||||
import { HeroDetailComponent } from './heroes/hero-detail.component.1';
|
import { HeroDetailComponent } from './heroes/hero-detail.component.1';
|
||||||
|
import { HeroListComponent } from './heroes/hero-list.component.1';
|
||||||
import { HeroService } from './heroes/hero.service';
|
import { HeroService } from './heroes/hero.service';
|
||||||
// #docregion
|
// #docregion
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
/* tslint:disable:no-unused-variable */
|
/* tslint:disable:no-unused-variable */
|
||||||
// #docplaster
|
// #docplaster
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { Routes, ROUTER_DIRECTIVES, Router } from '@angular/router';
|
import { Router, ROUTER_DIRECTIVES, Routes } from '@angular/router';
|
||||||
|
|
||||||
import { CrisisCenterComponent } from './crisis-center/crisis-center.component.1';
|
import { CrisisCenterComponent } from './crisis-center/crisis-center.component.1';
|
||||||
import { HeroListComponent } from './heroes/hero-list.component.1';
|
|
||||||
import { HeroDetailComponent } from './heroes/hero-detail.component.1';
|
import { HeroDetailComponent } from './heroes/hero-detail.component.1';
|
||||||
|
import { HeroListComponent } from './heroes/hero-list.component.1';
|
||||||
|
|
||||||
import { DialogService } from './dialog.service';
|
import { DialogService } from './dialog.service';
|
||||||
import { HeroService } from './heroes/hero.service';
|
import { HeroService } from './heroes/hero.service';
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { Routes, ROUTER_DIRECTIVES } from '@angular/router';
|
import { ROUTER_DIRECTIVES, Routes } from '@angular/router';
|
||||||
|
|
||||||
import { CrisisListComponent } from './crisis-list.component.1';
|
|
||||||
import { CrisisDetailComponent } from './crisis-detail.component.1';
|
import { CrisisDetailComponent } from './crisis-detail.component.1';
|
||||||
|
import { CrisisListComponent } from './crisis-list.component.1';
|
||||||
import { CrisisService } from './crisis.service';
|
import { CrisisService } from './crisis.service';
|
||||||
|
|
||||||
// #docregion minus-imports
|
// #docregion minus-imports
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { Routes, ROUTER_DIRECTIVES } from '@angular/router';
|
import { ROUTER_DIRECTIVES, Routes } from '@angular/router';
|
||||||
|
|
||||||
import { CrisisListComponent } from './crisis-list.component';
|
|
||||||
import { CrisisDetailComponent } from './crisis-detail.component';
|
import { CrisisDetailComponent } from './crisis-detail.component';
|
||||||
|
import { CrisisListComponent } from './crisis-list.component';
|
||||||
import { CrisisService } from './crisis.service';
|
import { CrisisService } from './crisis.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
import { OnActivate, Router, RouteSegment } from '@angular/router';
|
||||||
|
|
||||||
import { Crisis, CrisisService } from './crisis.service';
|
import { Crisis, CrisisService } from './crisis.service';
|
||||||
import { Router, OnActivate, RouteSegment } from '@angular/router';
|
|
||||||
// #docregion routerCanDeactivate
|
// #docregion routerCanDeactivate
|
||||||
// import { CanDeactivate } from '@angular/router';
|
// import { CanDeactivate } from '@angular/router';
|
||||||
import { DialogService } from '../dialog.service';
|
import { DialogService } from '../dialog.service';
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
import { CanDeactivate, OnActivate, Router, RouteSegment } from '@angular/router';
|
||||||
|
|
||||||
import { Crisis, CrisisService } from './crisis.service';
|
import { Crisis, CrisisService } from './crisis.service';
|
||||||
import { Router, OnActivate, CanDeactivate, RouteSegment } from '@angular/router';
|
|
||||||
import { DialogService } from '../dialog.service';
|
import { DialogService } from '../dialog.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -60,6 +61,7 @@ export class CrisisDetailComponent implements OnActivate, CanDeactivate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cancel() {
|
cancel() {
|
||||||
|
this.editName = this.crisis.name;
|
||||||
this.gotoCrises();
|
this.gotoCrises();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
import { OnActivate, Router, RouteSegment } from '@angular/router';
|
||||||
|
|
||||||
import { Crisis, CrisisService } from './crisis.service';
|
import { Crisis, CrisisService } from './crisis.service';
|
||||||
import { Router, OnActivate, RouteSegment } from '@angular/router';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
// #docregion template
|
// #docregion template
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
import { OnActivate, Router, RouteSegment, RouteTree } from '@angular/router';
|
||||||
|
|
||||||
import { Crisis, CrisisService } from './crisis.service';
|
import { Crisis, CrisisService } from './crisis.service';
|
||||||
import { Router, OnActivate, RouteSegment, RouteTree } from '@angular/router';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
template: `
|
template: `
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
import { OnActivate, Router, RouteSegment } from '@angular/router';
|
||||||
|
|
||||||
import { Hero, HeroService } from './hero.service';
|
import { Hero, HeroService } from './hero.service';
|
||||||
import { Router, OnActivate, RouteSegment } from '@angular/router';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
template: `
|
template: `
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
import { OnActivate, Router, RouteSegment } from '@angular/router';
|
||||||
|
|
||||||
import { Hero, HeroService } from './hero.service';
|
import { Hero, HeroService } from './hero.service';
|
||||||
import { Router, OnActivate, RouteSegment } from '@angular/router';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
template: `
|
template: `
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user