docs: update all docs to partially comply the style-guide
This commit is contained in:
parent
2ccdd867d2
commit
596825a8b1
|
@ -1,8 +1,8 @@
|
||||||
// #docregion import
|
// #docregion import
|
||||||
import {Component} from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
// #enddocregion import
|
// #enddocregion import
|
||||||
import {HeroListComponent} from './hero-list.component';
|
import { HeroListComponent } from './hero-list.component';
|
||||||
import {SalesTaxComponent} from './sales-tax.component';
|
import { SalesTaxComponent } from './sales-tax.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'my-app',
|
selector: 'my-app',
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {Injectable, Type} from '@angular/core';
|
import { Injectable, Type } from '@angular/core';
|
||||||
import {Logger} from './logger.service';
|
|
||||||
import {Hero} from './hero';
|
import { Logger } from './logger.service';
|
||||||
|
import { Hero } from './hero';
|
||||||
|
|
||||||
const HEROES = [
|
const HEROES = [
|
||||||
new Hero('Windstorm', 'Weather mastery'),
|
new Hero('Windstorm', 'Weather mastery'),
|
||||||
|
@ -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,5 +1,6 @@
|
||||||
import {Component, Input} from '@angular/core';
|
import { Component, Input} from '@angular/core';
|
||||||
import {Hero} from './hero';
|
|
||||||
|
import { Hero } from './hero';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'hero-detail',
|
selector: 'hero-detail',
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
// #docplaster
|
// #docplaster
|
||||||
import {Component, OnInit} from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import {Hero} from './hero';
|
|
||||||
import {HeroDetailComponent} from './hero-detail.component';
|
import { Hero } from './hero';
|
||||||
import {HeroService} from './hero.service';
|
import { HeroDetailComponent } from './hero-detail.component';
|
||||||
|
import { HeroService } from './hero.service';
|
||||||
|
|
||||||
// #docregion metadata
|
// #docregion metadata
|
||||||
// #docregion providers
|
// #docregion providers
|
||||||
|
@ -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,25 +1,26 @@
|
||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {Hero} from './hero';
|
|
||||||
import {BackendService} from './backend.service';
|
import { Hero } from './hero';
|
||||||
import {Logger} from './logger.service';
|
import { BackendService } from './backend.service';
|
||||||
|
import { Logger } from './logger.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
// #docregion class
|
// #docregion class
|
||||||
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,5 +1,5 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
// #docregion class
|
// #docregion class
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import {bootstrap} from '@angular/platform-browser-dynamic';
|
import { bootstrap } from '@angular/platform-browser-dynamic';
|
||||||
// #docregion import
|
// #docregion import
|
||||||
import {AppComponent} from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
// #enddocregion import
|
// #enddocregion import
|
||||||
import {HeroService} from './hero.service';
|
import { HeroService } from './hero.service';
|
||||||
import {BackendService} from './backend.service';
|
import { BackendService } from './backend.service';
|
||||||
import {Logger} from './logger.service';
|
import { Logger } from './logger.service';
|
||||||
|
|
||||||
// #docregion bootstrap
|
// #docregion bootstrap
|
||||||
bootstrap(AppComponent, [BackendService, HeroService, Logger]);
|
bootstrap(AppComponent, [BackendService, HeroService, Logger]);
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Component} from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import {SalesTaxService} from './sales-tax.service';
|
|
||||||
import {TaxRateService} from './tax-rate.service';
|
import { SalesTaxService } from './sales-tax.service';
|
||||||
|
import { TaxRateService } from './tax-rate.service';
|
||||||
|
|
||||||
// #docregion metadata
|
// #docregion metadata
|
||||||
// #docregion providers
|
// #docregion providers
|
||||||
|
@ -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,5 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
// #docregion class
|
// #docregion class
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Component} from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import {HighlightDirective} from './highlight.directive';
|
|
||||||
|
import { HighlightDirective } from './highlight.directive';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'my-app',
|
selector: 'my-app',
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Directive, ElementRef, Input} from '@angular/core';
|
import { Directive, ElementRef, Input } from '@angular/core';
|
||||||
|
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[myHighlight]'
|
selector: '[myHighlight]'
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Directive, ElementRef, Input} from '@angular/core';
|
import { Directive, ElementRef, Input } from '@angular/core';
|
||||||
|
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[myHighlight]',
|
selector: '[myHighlight]',
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion full
|
// #docregion full
|
||||||
import {Directive, ElementRef, Input} from '@angular/core';
|
import { Directive, ElementRef, Input } from '@angular/core';
|
||||||
|
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[myHighlight]',
|
selector: '[myHighlight]',
|
||||||
|
@ -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,10 +1,10 @@
|
||||||
import {Component} from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import {RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from '@angular/router-deprecated';
|
import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from '@angular/router-deprecated';
|
||||||
|
|
||||||
import {MovieListComponent} from './movie-list.component';
|
import { MovieListComponent } from './movie-list.component';
|
||||||
import {MovieService} from './movie.service';
|
import { MovieService } from './movie.service';
|
||||||
import {IMovie} from './movie';
|
import { IMovie } from './movie';
|
||||||
import {StringSafeDatePipe} from './date.pipe';
|
import { StringSafeDatePipe } from './date.pipe';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'my-app',
|
selector: 'my-app',
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import {Injectable, Pipe} from '@angular/core';
|
import { Injectable, Pipe } from '@angular/core';
|
||||||
import {DatePipe} from '@angular/common';
|
import { DatePipe } from '@angular/common';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
// #docregion date-pipe
|
// #docregion date-pipe
|
||||||
|
|
|
@ -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,11 +1,11 @@
|
||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion import
|
// #docregion import
|
||||||
import {Component} from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import {ROUTER_DIRECTIVES} from '@angular/router-deprecated';
|
import { ROUTER_DIRECTIVES } from '@angular/router-deprecated';
|
||||||
// #enddocregion import
|
// #enddocregion import
|
||||||
import {MovieService} from './movie.service';
|
import { MovieService } from './movie.service';
|
||||||
import {IMovie} from './movie';
|
import { IMovie } from './movie';
|
||||||
import {StringSafeDatePipe} from './date.pipe';
|
import { StringSafeDatePipe } from './date.pipe';
|
||||||
|
|
||||||
|
|
||||||
// #docregion component
|
// #docregion component
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {IMovie} from './movie';
|
|
||||||
|
import { IMovie } from './movie';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MovieService {
|
export class MovieService {
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import {Component} from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import {HeroParentComponent} from './hero-parent.component';
|
|
||||||
import {NameParentComponent} from './name-parent.component';
|
import { HeroParentComponent } from './hero-parent.component';
|
||||||
import {VersionParentComponent} from './version-parent.component';
|
import { NameParentComponent } from './name-parent.component';
|
||||||
import {VoteTakerComponent} from './votetaker.component';
|
import { VersionParentComponent } from './version-parent.component';
|
||||||
import {CountdownLocalVarParentComponent,
|
import { VoteTakerComponent } from './votetaker.component';
|
||||||
CountdownViewChildParentComponent} from './countdown-parent.component';
|
import { CountdownLocalVarParentComponent,
|
||||||
import {MissionControlComponent} from './missioncontrol.component';
|
CountdownViewChildParentComponent } from './countdown-parent.component';
|
||||||
|
import { MissionControlComponent } from './missioncontrol.component';
|
||||||
|
|
||||||
let directives: any[] = [
|
let directives: any[] = [
|
||||||
HeroParentComponent,
|
HeroParentComponent,
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Component, Input, OnDestroy} from '@angular/core';
|
import { Component, Input, OnDestroy } from '@angular/core';
|
||||||
import {MissionService} from './mission.service';
|
|
||||||
import {Subscription} from 'rxjs/Subscription';
|
import { MissionService } from './mission.service';
|
||||||
|
import { Subscription } from 'rxjs/Subscription';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'my-astronaut',
|
selector: 'my-astronaut',
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion vc
|
// #docregion vc
|
||||||
import {AfterViewInit, ViewChild} from '@angular/core';
|
import { AfterViewInit, ViewChild } from '@angular/core';
|
||||||
// #docregion lv
|
// #docregion lv
|
||||||
import {Component} from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import {CountdownTimerComponent} from './countdown-timer.component';
|
import { CountdownTimerComponent } from './countdown-timer.component';
|
||||||
|
|
||||||
// #enddocregion lv
|
// #enddocregion lv
|
||||||
// #enddocregion vc
|
// #enddocregion vc
|
||||||
|
@ -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,6 +1,7 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Component, Input} from '@angular/core';
|
import { Component, Input } from '@angular/core';
|
||||||
import {Hero} from './hero';
|
|
||||||
|
import { Hero } from './hero';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'hero-child',
|
selector: 'hero-child',
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Component} from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import {HeroChildComponent} from './hero-child.component';
|
|
||||||
import {HEROES} from './hero';
|
import { HeroChildComponent } from './hero-child.component';
|
||||||
|
import { HEROES } from './hero';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'hero-parent',
|
selector: 'hero-parent',
|
||||||
|
|
|
@ -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);
|
|
@ -1,25 +1,25 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Injectable} from '@angular/core'
|
import { Injectable } from '@angular/core'
|
||||||
import {Subject} from 'rxjs/Subject';
|
import { Subject } from 'rxjs/Subject';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
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,7 +1,8 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Component} from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import {AstronautComponent} from './astronaut.component';
|
|
||||||
import {MissionService} from './mission.service';
|
import { AstronautComponent } from './astronaut.component';
|
||||||
|
import { MissionService } from './mission.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'mission-control',
|
selector: 'mission-control',
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Component, Input} from '@angular/core';
|
import { Component, Input } from '@angular/core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'name-child',
|
selector: 'name-child',
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// #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({
|
||||||
selector: 'name-parent',
|
selector: 'name-parent',
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* tslint:disable:forin */
|
/* tslint:disable:forin */
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Component, Input, OnChanges, SimpleChange} from '@angular/core';
|
import { Component, Input, OnChanges, SimpleChange } from '@angular/core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'version-child',
|
selector: 'version-child',
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// #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({
|
||||||
selector: 'version-parent',
|
selector: 'version-parent',
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Component, EventEmitter, Input, Output} from '@angular/core';
|
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'my-voter',
|
selector: 'my-voter',
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Component} from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import {VoterComponent} from './voter.component';
|
|
||||||
|
import { VoterComponent } from './voter.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'vote-taker',
|
selector: 'vote-taker',
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Component, Input, OnInit} from '@angular/core';
|
import { Component, Input, OnInit } from '@angular/core';
|
||||||
|
|
||||||
import {Hero} from './hero';
|
import { Hero } from './hero';
|
||||||
import {HeroCacheService} from './hero-cache.service';
|
import { HeroCacheService } from './hero-cache.service';
|
||||||
|
|
||||||
// #docregion component
|
// #docregion component
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -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,17 +1,18 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {Hero} from './hero';
|
|
||||||
import {HeroService} from './hero.service';
|
import { Hero } from './hero';
|
||||||
|
import { HeroService } from './hero.service';
|
||||||
|
|
||||||
// #docregion service
|
// #docregion 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,8 +1,9 @@
|
||||||
// #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 {LoggerService} from './logger.service';
|
import { HeroCacheService } from './hero-cache.service';
|
||||||
|
import { LoggerService } from './logger.service';
|
||||||
|
|
||||||
// #docregion component
|
// #docregion component
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -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
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Hero} from './hero';
|
import { Hero } from './hero';
|
||||||
|
|
||||||
export class HeroData {
|
export class HeroData {
|
||||||
createDb() {
|
createDb() {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* tslint:disable:one-line:check-open-brace*/
|
/* tslint:disable:one-line:check-open-brace*/
|
||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion opaque-token
|
// #docregion opaque-token
|
||||||
import {OpaqueToken} from '@angular/core';
|
import { OpaqueToken } from '@angular/core';
|
||||||
|
|
||||||
export const TITLE = new OpaqueToken('title');
|
export const TITLE = new OpaqueToken('title');
|
||||||
// #enddocregion opaque-token
|
// #enddocregion opaque-token
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {Hero} from './hero';
|
import { Hero } from './hero';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Directive, ElementRef, Input} from '@angular/core';
|
import { Directive, ElementRef, Input } from '@angular/core';
|
||||||
|
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[myHighlight]',
|
selector: '[myHighlight]',
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class LoggerService {
|
export class LoggerService {
|
||||||
|
|
|
@ -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,8 +1,9 @@
|
||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
import {OpaqueToken} from '@angular/core';
|
import { OpaqueToken } from '@angular/core';
|
||||||
import {Hero} from './hero';
|
|
||||||
import {HeroService} from './hero.service';
|
import { Hero } from './hero';
|
||||||
|
import { HeroService } from './hero.service';
|
||||||
|
|
||||||
// #docregion runners-up
|
// #docregion runners-up
|
||||||
export const RUNNERS_UP = new OpaqueToken('RunnersUp');
|
export const RUNNERS_UP = new OpaqueToken('RunnersUp');
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Component, OnInit} from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import {Hero} from './hero';
|
|
||||||
import {HeroService} from './hero.service';
|
import { Hero } from './hero';
|
||||||
|
import { HeroService } from './hero.service';
|
||||||
|
|
||||||
/////// HeroesBaseComponent /////
|
/////// HeroesBaseComponent /////
|
||||||
// #docregion heroes-base, injection
|
// #docregion heroes-base, injection
|
||||||
|
@ -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,8 +1,9 @@
|
||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {LoggerService} from './logger.service';
|
|
||||||
import {UserService} from './user.service';
|
import { LoggerService } from './logger.service';
|
||||||
|
import { UserService } from './user.service';
|
||||||
|
|
||||||
// #docregion injectables, injectable
|
// #docregion injectables, injectable
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -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,5 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UserService {
|
export class UserService {
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Component} from '@angular/core'
|
import { Component } from '@angular/core'
|
||||||
import {DynamicForm} from './dynamic-form.component';
|
|
||||||
import {QuestionService} from './question.service';
|
import { DynamicForm } from './dynamic-form.component';
|
||||||
|
import { QuestionService } from './question.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'my-app',
|
selector: 'my-app',
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
// #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({
|
||||||
selector:'df-question',
|
selector:'df-question',
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Component, Input, OnInit} from '@angular/core';
|
import { Component, Input, OnInit } from '@angular/core';
|
||||||
import {ControlGroup} from '@angular/common';
|
import { ControlGroup } from '@angular/common';
|
||||||
|
|
||||||
import {QuestionBase} from './question-base';
|
import { QuestionBase } from './question-base';
|
||||||
import {QuestionControlService} from './question-control.service';
|
import { QuestionControlService } from './question-control.service';
|
||||||
import {DynamicFormQuestionComponent} from './dynamic-form-question.component';
|
import { DynamicFormQuestionComponent } from './dynamic-form-question.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector:'dynamic-form',
|
selector:'dynamic-form',
|
||||||
|
@ -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,5 +1,6 @@
|
||||||
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, [])
|
||||||
.catch((err:any) => console.error(err));
|
.catch((err:any) => console.error(err));
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {ControlGroup, FormBuilder, Validators} from '@angular/common';
|
import { ControlGroup, FormBuilder, Validators } from '@angular/common';
|
||||||
import {QuestionBase} from './question-base';
|
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,5 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {QuestionBase} from './question-base';
|
import { QuestionBase } from './question-base';
|
||||||
|
|
||||||
export class DropdownQuestion extends QuestionBase<string>{
|
export class DropdownQuestion extends QuestionBase<string>{
|
||||||
controlType = 'dropdown';
|
controlType = 'dropdown';
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {QuestionBase} from './question-base';
|
import { QuestionBase } from './question-base';
|
||||||
|
|
||||||
export class TextboxQuestion extends QuestionBase<string>{
|
export class TextboxQuestion extends QuestionBase<string>{
|
||||||
controlType = 'textbox';
|
controlType = 'textbox';
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {QuestionBase} from './question-base';
|
|
||||||
import {DynamicForm} from './dynamic-form.component';
|
import { QuestionBase } from './question-base';
|
||||||
import {TextboxQuestion} from './question-textbox';
|
import { DynamicForm } from './dynamic-form.component';
|
||||||
import {DropdownQuestion} from './question-dropdown';
|
import { TextboxQuestion } from './question-textbox';
|
||||||
|
import { DropdownQuestion } from './question-dropdown';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class QuestionService {
|
export class QuestionService {
|
||||||
|
|
|
@ -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,4 @@
|
||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DataService {
|
export class DataService {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {Component, Inject} from '@angular/core';
|
import { Component, Inject } from '@angular/core';
|
||||||
|
|
||||||
// #docregion
|
// #docregion
|
||||||
@Component({
|
@Component({
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import {Component} from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import {DataService} from './data.service';
|
|
||||||
|
import { DataService } from './data.service';
|
||||||
|
|
||||||
// #docregion
|
// #docregion
|
||||||
@Component({
|
@Component({
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {Component, EventEmitter, Input, Output} from '@angular/core';
|
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
||||||
|
|
||||||
// #docregion
|
// #docregion
|
||||||
@Component({
|
@Component({
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Component, OnInit}
|
import { Component, OnInit }
|
||||||
from '@angular/core';
|
from '@angular/core';
|
||||||
// #enddocregion
|
// #enddocregion
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion metadata
|
// #docregion metadata
|
||||||
import {Component} from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'hero-view',
|
selector: 'hero-view',
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import {Component, HostBinding, HostListener} from '@angular/core';
|
import { Component, HostBinding, HostListener } from '@angular/core';
|
||||||
|
|
||||||
// #docregion
|
// #docregion
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'heroes-bindings',
|
selector: 'heroes-bindings',
|
||||||
template: `<h1 [class.active]="active">
|
template: `<h1 [class.active]="active">
|
||||||
Tour of Heroes
|
Tour ofHeroes
|
||||||
</h1>`
|
</h1>`
|
||||||
})
|
})
|
||||||
export class HeroesComponent {
|
export class HeroesComponent {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// #docregion ng2import
|
// #docregion ng2import
|
||||||
import {provide}
|
import { provide }
|
||||||
from '@angular/core';
|
from '@angular/core';
|
||||||
import {bootstrap}
|
import { bootstrap }
|
||||||
from '@angular/platform-browser-dynamic';
|
from '@angular/platform-browser-dynamic';
|
||||||
import {
|
import {
|
||||||
} from '@angular/router';
|
} from '@angular/router';
|
||||||
|
@ -12,18 +12,18 @@ import {
|
||||||
// #enddocregion ng2import
|
// #enddocregion ng2import
|
||||||
|
|
||||||
// #docregion appimport
|
// #docregion appimport
|
||||||
import {HeroComponent}
|
import { HeroComponent }
|
||||||
from './hero.component';
|
from './hero.component';
|
||||||
// #enddocregion appimport
|
// #enddocregion appimport
|
||||||
import {HeroComponent as HeroLifecycleComponent} from './hero-lifecycle.component';
|
import { HeroComponent as HeroLifecycleComponent } from './hero-lifecycle.component';
|
||||||
import {HeroComponent as HeroDIComponent} from './hero-di.component';
|
import { HeroComponent as HeroDIComponent } from './hero-di.component';
|
||||||
import {HeroComponent as HeroDIInjectComponent} from './hero-di-inject.component';
|
import { HeroComponent as HeroDIInjectComponent } from './hero-di-inject.component';
|
||||||
import {AppComponent as AppDIInjectAdditionalComponent} from './hero-di-inject-additional.component';
|
import { AppComponent as AppDIInjectAdditionalComponent } from './hero-di-inject-additional.component';
|
||||||
import {AppComponent as AppIOComponent} from './hero-io.component';
|
import { AppComponent as AppIOComponent } from './hero-io.component';
|
||||||
import {HeroesComponent as HeroesHostBindingsComponent} from './heroes-bindings.component';
|
import { HeroesComponent as HeroesHostBindingsComponent } from './heroes-bindings.component';
|
||||||
import {HeroesQueriesComponent} from './heroes-queries.component';
|
import { HeroesQueriesComponent } from './heroes-queries.component';
|
||||||
|
|
||||||
import {DataService} from './data.service';
|
import { DataService } from './data.service';
|
||||||
|
|
||||||
bootstrap(HeroComponent);
|
bootstrap(HeroComponent);
|
||||||
bootstrap(HeroLifecycleComponent);
|
bootstrap(HeroLifecycleComponent);
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import {Component, Input} from '@angular/core';
|
import { Component, Input } from '@angular/core';
|
||||||
import {Hero} from './hero';
|
|
||||||
import {HeroDetailsComponent} from './hero-details.component';
|
import { Hero } from './hero';
|
||||||
import {HeroControlsComponent} from './hero-controls.component';
|
import { HeroDetailsComponent } from './hero-details.component';
|
||||||
import {QuestSummaryComponent} from './quest-summary.component';
|
import { HeroControlsComponent } from './hero-controls.component';
|
||||||
|
import { QuestSummaryComponent } from './quest-summary.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'hero-app-main',
|
selector: 'hero-app-main',
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import {Component, HostBinding} from '@angular/core';
|
import { Component, HostBinding } from '@angular/core';
|
||||||
import {Hero} from './hero';
|
import { Hero } from './hero';
|
||||||
import {HeroAppMainComponent} from './hero-app-main.component';
|
import { HeroAppMainComponent } from './hero-app-main.component';
|
||||||
|
|
||||||
// #docregion
|
// #docregion
|
||||||
@Component({
|
@Component({
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import {Component, Input} from '@angular/core';
|
import { Component, Input } from '@angular/core';
|
||||||
import {Hero} from './hero';
|
import { Hero } from './hero';
|
||||||
|
|
||||||
// #docregion inlinestyles
|
// #docregion inlinestyles
|
||||||
@Component({
|
@Component({
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import {Component, Input} from '@angular/core';
|
import { Component, Input } from '@angular/core';
|
||||||
import {Hero} from './hero';
|
import { Hero } from './hero';
|
||||||
import {HeroTeamComponent} from './hero-team.component';
|
import { HeroTeamComponent } from './hero-team.component';
|
||||||
|
|
||||||
// #docregion styleurls
|
// #docregion styleurls
|
||||||
@Component({
|
@Component({
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import {Component, Input} from '@angular/core';
|
import { Component, Input } from '@angular/core';
|
||||||
import {Hero} from './hero';
|
import { Hero } from './hero';
|
||||||
|
|
||||||
// #docregion stylelink
|
// #docregion stylelink
|
||||||
@Component({
|
@Component({
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {bootstrap} from '@angular/platform-browser-dynamic';
|
import { bootstrap } from '@angular/platform-browser-dynamic';
|
||||||
import {HeroAppComponent} from './hero-app.component';
|
import { HeroAppComponent } from './hero-app.component';
|
||||||
|
|
||||||
bootstrap(HeroAppComponent);
|
bootstrap(HeroAppComponent);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* tslint:disable:no-unused-variable */
|
/* tslint:disable:no-unused-variable */
|
||||||
// #docplaster
|
// #docplaster
|
||||||
import {Component, ViewEncapsulation} from '@angular/core';
|
import { Component, ViewEncapsulation } from '@angular/core';
|
||||||
|
|
||||||
// #docregion
|
// #docregion
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
// Early versions
|
// Early versions
|
||||||
|
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Component} from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import {CarComponent} from './car/car.component';
|
|
||||||
import {HeroesComponent} from './heroes/heroes.component.1';
|
import { CarComponent } from './car/car.component';
|
||||||
|
import { HeroesComponent } from './heroes/heroes.component.1';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'my-app',
|
selector: 'my-app',
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
// #docregion imports
|
// #docregion imports
|
||||||
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';
|
||||||
|
|
||||||
import {provide, Inject} from '@angular/core';
|
import { provide, Inject } from '@angular/core';
|
||||||
import {Config, CONFIG} from './app.config';
|
import { Config, CONFIG } from './app.config';
|
||||||
import {Logger} from './logger.service';
|
import { Logger } from './logger.service';
|
||||||
// #enddocregion imports
|
// #enddocregion imports
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
// #docregion imports
|
// #docregion imports
|
||||||
import {Component, Inject, provide} from '@angular/core';
|
import { Component, Inject, provide } from '@angular/core';
|
||||||
|
|
||||||
import {CarComponent} from './car/car.component';
|
import { CarComponent } from './car/car.component';
|
||||||
import {HeroesComponent} from './heroes/heroes.component';
|
import { HeroesComponent } from './heroes/heroes.component';
|
||||||
|
|
||||||
import {APP_CONFIG,
|
import { APP_CONFIG,
|
||||||
Config, CONFIG} from './app.config';
|
Config, CONFIG } from './app.config';
|
||||||
import {Logger} from './logger.service';
|
import { Logger } from './logger.service';
|
||||||
|
|
||||||
import {User, UserService} from './user.service';
|
import { User, UserService } from './user.service';
|
||||||
// #enddocregion imports
|
// #enddocregion imports
|
||||||
import {InjectorComponent} from './injector.component';
|
import { InjectorComponent } from './injector.component';
|
||||||
import {TestComponent} from './test.component';
|
import { TestComponent } from './test.component';
|
||||||
import {ProvidersComponent} from './providers.component';
|
import { ProvidersComponent } from './providers.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'my-app',
|
selector: 'my-app',
|
||||||
|
@ -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,6 +1,6 @@
|
||||||
//#docregion
|
//#docregion
|
||||||
// #docregion token
|
// #docregion token
|
||||||
import {OpaqueToken} from '@angular/core';
|
import { OpaqueToken } from '@angular/core';
|
||||||
|
|
||||||
export let APP_CONFIG = new OpaqueToken('app.config');
|
export let APP_CONFIG = new OpaqueToken('app.config');
|
||||||
// #enddocregion token
|
// #enddocregion token
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Examples with car and engine variations
|
// Examples with car and engine variations
|
||||||
|
|
||||||
// #docplaster
|
// #docplaster
|
||||||
import {Car, Engine, Tires} from './car';
|
import { Car, Engine, Tires } from './car';
|
||||||
|
|
||||||
///////// example 1 ////////////
|
///////// example 1 ////////////
|
||||||
export function simpleCar() {
|
export function simpleCar() {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Engine, Tires, Car} from './car';
|
import { Engine, Tires, Car } from './car';
|
||||||
|
|
||||||
// BAD pattern!
|
// BAD pattern!
|
||||||
export class CarFactory {
|
export class CarFactory {
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
//#docregion
|
//#docregion
|
||||||
import { ReflectiveInjector } from '@angular/core';
|
import { ReflectiveInjector } from '@angular/core';
|
||||||
|
|
||||||
import {Car, Engine, Tires} from './car';
|
import { Car, Engine, Tires } from './car';
|
||||||
import {Logger} from '../logger.service';
|
import { Logger } from '../logger.service';
|
||||||
|
|
||||||
//#docregion injector
|
//#docregion injector
|
||||||
export function useInjector() {
|
export function useInjector() {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Car without DI
|
// Car without DI
|
||||||
import {Engine, Tires} from './car';
|
import { Engine, Tires } from './car';
|
||||||
|
|
||||||
//#docregion car
|
//#docregion car
|
||||||
export class Car {
|
export class Car {
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
// #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';
|
||||||
|
|
||||||
import { testCar,
|
import { testCar,
|
||||||
simpleCar,
|
simpleCar,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
// #docregion engine
|
// #docregion engine
|
||||||
export class Engine {
|
export class Engine {
|
||||||
|
|
|
@ -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,6 +1,6 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Hero} from './hero';
|
import { Hero } from './hero';
|
||||||
import {HEROES} from './mock-heroes';
|
import { HEROES } from './mock-heroes';
|
||||||
|
|
||||||
export class HeroService {
|
export class HeroService {
|
||||||
getHeroes() { return HEROES; }
|
getHeroes() { return HEROES; }
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {Hero} from './hero';
|
|
||||||
import {HEROES} from './mock-heroes';
|
import { Hero } from './hero';
|
||||||
import {Logger} from '../logger.service';
|
import { HEROES } from './mock-heroes';
|
||||||
|
import { Logger } from '../logger.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
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,8 +1,9 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {provide} from '@angular/core';
|
import { provide } from '@angular/core';
|
||||||
import {HeroService} from './hero.service';
|
|
||||||
import {Logger} from '../logger.service';
|
import { HeroService } from './hero.service';
|
||||||
import {UserService} from '../user.service';
|
import { Logger } from '../logger.service';
|
||||||
|
import { UserService } from '../user.service';
|
||||||
|
|
||||||
// #docregion factory
|
// #docregion factory
|
||||||
let heroServiceFactory = (logger: Logger, userService: UserService) => {
|
let heroServiceFactory = (logger: Logger, userService: UserService) => {
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {Hero} from './hero';
|
|
||||||
import {HEROES} from './mock-heroes';
|
import { Hero } from './hero';
|
||||||
import {Logger} from '../logger.service';
|
import { HEROES } from './mock-heroes';
|
||||||
|
import { Logger } from '../logger.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class HeroService {
|
export class HeroService {
|
||||||
|
@ -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';
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
// #docplaster
|
// #docplaster
|
||||||
//#docregion
|
//#docregion
|
||||||
import {Component, Injector} from '@angular/core';
|
import { Component, Injector } from '@angular/core';
|
||||||
|
|
||||||
import {Car, Engine, Tires} from './car/car';
|
import { Car, Engine, Tires } from './car/car';
|
||||||
import {HeroService} from './heroes/hero.service';
|
import { HeroService } from './heroes/hero.service';
|
||||||
import {heroServiceProvider} from './heroes/hero.service.provider';
|
import { heroServiceProvider } from './heroes/hero.service.provider';
|
||||||
import {Logger} from './logger.service';
|
import { Logger } from './logger.service';
|
||||||
|
|
||||||
//#docregion injector
|
//#docregion injector
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -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!')
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class Logger {
|
export class Logger {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import {bootstrap} from '@angular/platform-browser-dynamic';
|
import { bootstrap } from '@angular/platform-browser-dynamic';
|
||||||
import {AppComponent} from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
import {HeroService} from './heroes/hero.service';
|
import { HeroService } from './heroes/hero.service';
|
||||||
|
|
||||||
//#docregion bootstrap
|
//#docregion bootstrap
|
||||||
bootstrap(AppComponent,
|
bootstrap(AppComponent,
|
||||||
|
|
|
@ -1,7 +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';
|
||||||
import {ProvidersComponent} from './providers.component';
|
import { ProvidersComponent } from './providers.component';
|
||||||
|
|
||||||
//#docregion bootstrap
|
//#docregion bootstrap
|
||||||
bootstrap(AppComponent);
|
bootstrap(AppComponent);
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
// Examples of provider arrays
|
// Examples of provider arrays
|
||||||
//#docplaster
|
//#docplaster
|
||||||
import { Component, Host, Inject, Injectable,
|
import { Component, Host, Inject, Injectable,
|
||||||
provide, Provider} from '@angular/core';
|
provide, Provider } from '@angular/core';
|
||||||
|
|
||||||
import { APP_CONFIG,
|
import { APP_CONFIG,
|
||||||
Config, CONFIG } from './app.config';
|
Config, CONFIG } from './app.config';
|
||||||
|
|
||||||
import { HeroService} from './heroes/hero.service';
|
import { HeroService } from './heroes/hero.service';
|
||||||
import { heroServiceProvider } from './heroes/hero.service.provider';
|
import { heroServiceProvider } from './heroes/hero.service.provider';
|
||||||
import { Logger } from './logger.service';
|
import { Logger } from './logger.service';
|
||||||
import { User, UserService } from './user.service';
|
import { User, UserService } from './user.service';
|
||||||
|
@ -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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
// Simulate a simple test
|
// Simulate a simple test
|
||||||
// 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';
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {Component} from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'my-app-ctor',
|
selector: 'my-app-ctor',
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue