chore: tslint sweep done
This commit is contained in:
parent
1cc5284cc2
commit
074a33a622
|
@ -24,13 +24,13 @@ export class HeroesComponent { ... }
|
||||||
*/
|
*/
|
||||||
// #docregion class
|
// #docregion class
|
||||||
export class HeroListComponent implements OnInit {
|
export class HeroListComponent implements OnInit {
|
||||||
|
heroes: Hero[];
|
||||||
|
selectedHero: Hero;
|
||||||
|
|
||||||
// #docregion ctor
|
// #docregion ctor
|
||||||
constructor(private service: HeroService) { }
|
constructor(private service: HeroService) { }
|
||||||
// #enddocregion ctor
|
// #enddocregion ctor
|
||||||
|
|
||||||
heroes: Hero[];
|
|
||||||
selectedHero: Hero;
|
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.heroes = this.service.getHeroes();
|
this.heroes = this.service.getHeroes();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,14 +7,14 @@ import { Logger } from './logger.service';
|
||||||
@Injectable()
|
@Injectable()
|
||||||
// #docregion class
|
// #docregion class
|
||||||
export class HeroService {
|
export class HeroService {
|
||||||
|
private heroes: Hero[] = [];
|
||||||
|
|
||||||
// #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[] = [];
|
|
||||||
|
|
||||||
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.`);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Inject, Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { TaxRateService } from './tax-rate.service';
|
import { TaxRateService } from './tax-rate.service';
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* tslint:disable:no-unused-variable */
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Directive, ElementRef, Input } from '@angular/core';
|
import { Directive, ElementRef, Input } from '@angular/core';
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
|
/* tslint:disable:no-unused-variable */
|
||||||
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Directive, ElementRef, Input } from '@angular/core';
|
import { Directive, ElementRef, HostListener, Input } from '@angular/core';
|
||||||
|
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[myHighlight]',
|
selector: '[myHighlight]'
|
||||||
// #docregion host
|
|
||||||
host: {
|
|
||||||
'(mouseenter)': 'onMouseEnter()',
|
|
||||||
'(mouseleave)': 'onMouseLeave()'
|
|
||||||
}
|
|
||||||
// #enddocregion host
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export class HighlightDirective {
|
export class HighlightDirective {
|
||||||
|
@ -18,9 +14,19 @@ export class HighlightDirective {
|
||||||
constructor(el: ElementRef) { this.el = el.nativeElement; }
|
constructor(el: ElementRef) { this.el = el.nativeElement; }
|
||||||
// #enddocregion ctor
|
// #enddocregion ctor
|
||||||
|
|
||||||
// #docregion mouse-methods
|
// #docregion mouse-methods, host
|
||||||
onMouseEnter() { this.highlight('yellow'); }
|
@HostListener('mouseenter') onMouseEnter() {
|
||||||
onMouseLeave() { this.highlight(null); }
|
// #enddocregion host
|
||||||
|
this.highlight('yellow');
|
||||||
|
// #docregion host
|
||||||
|
}
|
||||||
|
|
||||||
|
@HostListener('mouseleave') onMouseLeave() {
|
||||||
|
// #enddocregion host
|
||||||
|
this.highlight(null);
|
||||||
|
// #docregion host
|
||||||
|
}
|
||||||
|
// #enddocregion host
|
||||||
|
|
||||||
private highlight(color: string) {
|
private highlight(color: string) {
|
||||||
this.el.style.backgroundColor = color;
|
this.el.style.backgroundColor = color;
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion full
|
// #docregion full
|
||||||
import { Directive, ElementRef, Input } from '@angular/core';
|
import { Directive, ElementRef, HostListener, Input } from '@angular/core';
|
||||||
|
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[myHighlight]',
|
selector: '[myHighlight]'
|
||||||
host: {
|
|
||||||
'(mouseenter)': 'onMouseEnter()',
|
|
||||||
'(mouseleave)': 'onMouseLeave()'
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
// #docregion class-1
|
// #docregion class-1
|
||||||
export class HighlightDirective {
|
export class HighlightDirective {
|
||||||
|
@ -29,9 +25,13 @@ export class HighlightDirective {
|
||||||
// #enddocregion color
|
// #enddocregion color
|
||||||
|
|
||||||
// #docregion mouse-enter
|
// #docregion mouse-enter
|
||||||
onMouseEnter() { this.highlight(this.highlightColor || this._defaultColor); }
|
@HostListener('mouseenter') onMouseEnter() {
|
||||||
|
this.highlight(this.highlightColor || this._defaultColor);
|
||||||
|
}
|
||||||
// #enddocregion mouse-enter
|
// #enddocregion mouse-enter
|
||||||
onMouseLeave() { this.highlight(null); }
|
@HostListener('mouseleave') onMouseLeave() {
|
||||||
|
this.highlight(null);
|
||||||
|
}
|
||||||
|
|
||||||
private highlight(color: string) {
|
private highlight(color: string) {
|
||||||
this.el.style.backgroundColor = color;
|
this.el.style.backgroundColor = color;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import { Injectable, Pipe } from '@angular/core';
|
import { Injectable, Pipe, PipeTransform } from '@angular/core';
|
||||||
import { DatePipe } from '@angular/common';
|
import { DatePipe } from '@angular/common';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
// #docregion date-pipe
|
// #docregion date-pipe
|
||||||
@Pipe({name: 'date', pure: true})
|
@Pipe({name: 'date', pure: true})
|
||||||
export class StringSafeDatePipe extends DatePipe {
|
export class StringSafeDatePipe extends DatePipe implements PipeTransform {
|
||||||
transform(value: any, format: string): string {
|
transform(value: any, format: string): string {
|
||||||
value = typeof value === 'string' ?
|
value = typeof value === 'string' ?
|
||||||
Date.parse(value) : value;
|
Date.parse(value) : value;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* tslint:disable:no-unused-variable */
|
||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion import
|
// #docregion import
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
|
@ -25,7 +25,7 @@ if (!/e2e/.test(location.search)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app',
|
selector: 'my-app',
|
||||||
templateUrl: 'app/app.component.html',
|
templateUrl: 'app/app.component.html',
|
||||||
directives: directives
|
directives: directives
|
||||||
})
|
})
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<app>loading...</app>
|
<my-app>loading...</my-app>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Component, Input, OnInit } from '@angular/core';
|
import { Component, Input, OnInit } from '@angular/core';
|
||||||
|
|
||||||
import { Hero } from './hero';
|
|
||||||
import { HeroCacheService } from './hero-cache.service';
|
import { HeroCacheService } from './hero-cache.service';
|
||||||
|
|
||||||
// #docregion component
|
// #docregion component
|
||||||
|
@ -17,7 +16,6 @@ import { HeroCacheService } from './hero-cache.service';
|
||||||
})
|
})
|
||||||
|
|
||||||
export class HeroBioComponent implements OnInit {
|
export class HeroBioComponent implements OnInit {
|
||||||
|
|
||||||
@Input() heroId: number;
|
@Input() heroId: number;
|
||||||
|
|
||||||
constructor(private heroCache: HeroCacheService) { }
|
constructor(private heroCache: HeroCacheService) { }
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Component} from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { HeroContactComponent } from './hero-contact.component';
|
import { HeroContactComponent } from './hero-contact.component';
|
||||||
import { HeroBioComponent } from './hero-bio.component';
|
import { HeroBioComponent } from './hero-bio.component';
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Component, ElementRef, Host, Inject, Optional } from '@angular/core';
|
import { Component, Host, 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';
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Directive, ElementRef, Input } from '@angular/core';
|
import { Directive, ElementRef, HostListener, Input } from '@angular/core';
|
||||||
|
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[myHighlight]',
|
selector: '[myHighlight]'
|
||||||
host: {
|
|
||||||
'(mouseenter)': 'onMouseEnter()',
|
|
||||||
'(mouseleave)': 'onMouseLeave()'
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
export class HighlightDirective {
|
export class HighlightDirective {
|
||||||
|
|
||||||
|
@ -19,8 +15,13 @@ export class HighlightDirective {
|
||||||
this.el = el.nativeElement;
|
this.el = el.nativeElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
onMouseEnter() { this.highlight(this.highlightColor || 'cyan'); }
|
@HostListener('mouseenter') onMouseEnter() {
|
||||||
onMouseLeave() { this.highlight(null); }
|
this.highlight(this.highlightColor || 'cyan');
|
||||||
|
}
|
||||||
|
|
||||||
|
@HostListener('mouseleave') 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 @@
|
||||||
/* tslint:disable:no-unused-variable */
|
/* tslint:disable:no-unused-variable component-selector-name one-line check-open-brace */
|
||||||
/* tslint:disable:one-line:check-open-brace*/
|
/* tslint:disable:*/
|
||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Component, forwardRef, Optional, provide, SkipSelf } from '@angular/core';
|
import { Component, forwardRef, Optional, provide, SkipSelf } from '@angular/core';
|
||||||
|
@ -23,7 +23,7 @@ const provideParent =
|
||||||
// #enddocregion provide-parent, provide-the-parent
|
// #enddocregion provide-parent, provide-the-parent
|
||||||
// #docregion provide-parent
|
// #docregion provide-parent
|
||||||
(component: any, parentType?: any) => {
|
(component: any, parentType?: any) => {
|
||||||
return { provide: parentType || Parent, useExisting: forwardRef(() => component) };
|
return { provide: parentType || Parent, useExisting: forwardRef(() => component) };
|
||||||
};
|
};
|
||||||
// #enddocregion provide-parent
|
// #enddocregion provide-parent
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { DynamicForm } from './dynamic-form.component';
|
import { DynamicFormComponent } from './dynamic-form.component';
|
||||||
import { QuestionService } from './question.service';
|
import { QuestionService } from './question.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -12,7 +12,7 @@ import { QuestionService } from './question.service';
|
||||||
<dynamic-form [questions]="questions"></dynamic-form>
|
<dynamic-form [questions]="questions"></dynamic-form>
|
||||||
</div>
|
</div>
|
||||||
`,
|
`,
|
||||||
directives: [DynamicForm],
|
directives: [DynamicFormComponent],
|
||||||
providers: [QuestionService]
|
providers: [QuestionService]
|
||||||
})
|
})
|
||||||
export class AppComponent {
|
export class AppComponent {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import { DynamicFormQuestionComponent } from './dynamic-form-question.component'
|
||||||
directives: [DynamicFormQuestionComponent],
|
directives: [DynamicFormQuestionComponent],
|
||||||
providers: [QuestionControlService]
|
providers: [QuestionControlService]
|
||||||
})
|
})
|
||||||
export class DynamicForm {
|
export class DynamicFormComponent implements OnInit {
|
||||||
|
|
||||||
@Input() questions: QuestionBase<any>[] = [];
|
@Input() questions: QuestionBase<any>[] = [];
|
||||||
form: ControlGroup;
|
form: ControlGroup;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { ControlGroup, FormBuilder, Validators } from '@angular/common';
|
import { FormBuilder, Validators } from '@angular/common';
|
||||||
import { QuestionBase } from './question-base';
|
import { QuestionBase } from './question-base';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
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 { TextboxQuestion } from './question-textbox';
|
import { TextboxQuestion } from './question-textbox';
|
||||||
import { DropdownQuestion } from './question-dropdown';
|
import { DropdownQuestion } from './question-dropdown';
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ describe('TypeScript to Javascript tests', function () {
|
||||||
|
|
||||||
it('should support content and view queries', function() {
|
it('should support content and view queries', function() {
|
||||||
let app = element(by.css('heroes-queries'));
|
let app = element(by.css('heroes-queries'));
|
||||||
let windstorm = app.element(by.css('hero:first-child'));
|
let windstorm = app.element(by.css('a-hero:first-child'));
|
||||||
|
|
||||||
app.element(by.buttonText('Activate')).click();
|
app.element(by.buttonText('Activate')).click();
|
||||||
expect(windstorm.element(by.css('h2')).getAttribute('class')).toBe('active');
|
expect(windstorm.element(by.css('h2')).getAttribute('class')).toBe('active');
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
// #docregion content
|
// #docregion content
|
||||||
var HeroComponent = ng.core.Component({
|
var HeroComponent = ng.core.Component({
|
||||||
selector: 'hero',
|
selector: 'a-hero',
|
||||||
template: '<h2 [class.active]=active>' +
|
template: '<h2 [class.active]=active>' +
|
||||||
'{{hero.name}} ' +
|
'{{hero.name}} ' +
|
||||||
'<ng-content></ng-content>' +
|
'<ng-content></ng-content>' +
|
||||||
|
@ -38,10 +38,10 @@
|
||||||
var AppComponent = ng.core.Component({
|
var AppComponent = ng.core.Component({
|
||||||
selector: 'heroes-queries',
|
selector: 'heroes-queries',
|
||||||
template:
|
template:
|
||||||
'<hero *ngFor="let hero of heroData"' +
|
'<a-hero *ngFor="let hero of heroData"' +
|
||||||
'[hero]="hero">' +
|
'[hero]="hero">' +
|
||||||
'<active-label></active-label>' +
|
'<active-label></active-label>' +
|
||||||
'</hero>' +
|
'</a-hero>' +
|
||||||
'<button (click)="activate()">' +
|
'<button (click)="activate()">' +
|
||||||
'Activate' +
|
'Activate' +
|
||||||
'</button>',
|
'</button>',
|
||||||
|
|
|
@ -23,7 +23,7 @@ class ActiveLabelComponent {
|
||||||
|
|
||||||
// #docregion content
|
// #docregion content
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'hero',
|
selector: 'a-hero',
|
||||||
template: `<h2 [class.active]=active>
|
template: `<h2 [class.active]=active>
|
||||||
{{hero.name}}
|
{{hero.name}}
|
||||||
<ng-content></ng-content>
|
<ng-content></ng-content>
|
||||||
|
@ -48,10 +48,10 @@ class HeroComponent {
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'heroes-queries',
|
selector: 'heroes-queries',
|
||||||
template: `
|
template: `
|
||||||
<hero *ngFor="let hero of heroData"
|
<a-hero *ngFor="let hero of heroData"
|
||||||
[hero]="hero">
|
[hero]="hero">
|
||||||
<active-label></active-label>
|
<active-label></active-label>
|
||||||
</hero>
|
</a-hero>
|
||||||
<button (click)="activate()">
|
<button (click)="activate()">
|
||||||
Activate
|
Activate
|
||||||
</button>
|
</button>
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* tslint:disable no-unused-variable */
|
||||||
// #docregion ng2import
|
// #docregion ng2import
|
||||||
import { bootstrap }
|
import { bootstrap }
|
||||||
from '@angular/platform-browser-dynamic';
|
from '@angular/platform-browser-dynamic';
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
describe('cli-quickstart App', () => {
|
describe('cli-quickstart App', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
return browser.get('/');
|
return browser.get('/');
|
||||||
})
|
});
|
||||||
|
|
||||||
it('should display message saying app works', () => {
|
it('should display message saying app works', () => {
|
||||||
var pageTitle = element(by.css('cli-quickstart-app h1')).getText()
|
let pageTitle = element(by.css('cli-quickstart-app h1')).getText();
|
||||||
expect(pageTitle).toEqual('My First Angular 2 App');
|
expect(pageTitle).toEqual('My First Angular 2 App');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { APP_CONFIG, AppConfig,
|
||||||
HERO_DI_CONFIG } from './app.config';
|
HERO_DI_CONFIG } from './app.config';
|
||||||
import { Logger } from './logger.service';
|
import { Logger } from './logger.service';
|
||||||
|
|
||||||
import { User, UserService } from './user.service';
|
import { 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';
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Component, Injector } from '@angular/core';
|
import { Component } 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';
|
||||||
|
@ -27,12 +27,12 @@ import { useInjector } from './car-injector';
|
||||||
providers: [Car, Engine, Tires]
|
providers: [Car, Engine, Tires]
|
||||||
})
|
})
|
||||||
export class CarComponent {
|
export class CarComponent {
|
||||||
constructor(public car: Car) {}
|
|
||||||
|
|
||||||
factoryCar = (new CarFactory).createCar();
|
factoryCar = (new CarFactory).createCar();
|
||||||
injectorCar = useInjector();
|
injectorCar = useInjector();
|
||||||
noDiCar = new CarNoDi;
|
noDiCar = new CarNoDi;
|
||||||
simpleCar = simpleCar();
|
simpleCar = simpleCar();
|
||||||
superCar = superCar();
|
superCar = superCar();
|
||||||
testCar = testCar();
|
testCar = testCar();
|
||||||
|
|
||||||
|
constructor(public car: Car) {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { Hero } from './hero';
|
|
||||||
import { HEROES } from './mock-heroes';
|
import { HEROES } from './mock-heroes';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { Hero } from './hero';
|
|
||||||
import { HEROES } from './mock-heroes';
|
import { HEROES } from './mock-heroes';
|
||||||
import { Logger } from '../logger.service';
|
import { Logger } from '../logger.service';
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { Hero } from './hero';
|
|
||||||
import { HEROES } from './mock-heroes';
|
import { HEROES } from './mock-heroes';
|
||||||
import { Logger } from '../logger.service';
|
import { Logger } from '../logger.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class HeroService {
|
export class HeroService {
|
||||||
private _user: string;
|
|
||||||
|
|
||||||
// #docregion internals
|
// #docregion internals
|
||||||
constructor(
|
constructor(
|
||||||
private logger: Logger,
|
private logger: Logger,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* tslint:disable:one-line:check-open-brace*/
|
/* tslint:disable:one-line:check-open-brace*/
|
||||||
// Examples of provider arrays
|
// Examples of provider arrays
|
||||||
// #docplaster
|
// #docplaster
|
||||||
import { Component, Inject, Injectable } from '@angular/core';
|
import { Component, Inject, Injectable, OnInit } from '@angular/core';
|
||||||
|
|
||||||
import { APP_CONFIG, AppConfig,
|
import { APP_CONFIG, AppConfig,
|
||||||
HERO_DI_CONFIG } from './app.config';
|
HERO_DI_CONFIG } from './app.config';
|
||||||
|
@ -21,7 +21,7 @@ let template = '{{log}}';
|
||||||
providers: [Logger]
|
providers: [Logger]
|
||||||
// #enddocregion providers-1, providers-logger
|
// #enddocregion providers-1, providers-logger
|
||||||
})
|
})
|
||||||
export class ProviderComponent1 {
|
export class Provider1Component {
|
||||||
log: string;
|
log: string;
|
||||||
constructor(logger: Logger) {
|
constructor(logger: Logger) {
|
||||||
logger.log('Hello from logger provided with Logger class');
|
logger.log('Hello from logger provided with Logger class');
|
||||||
|
@ -38,7 +38,7 @@ export class ProviderComponent1 {
|
||||||
[{ provide: Logger, useClass: Logger }]
|
[{ provide: Logger, useClass: Logger }]
|
||||||
// #enddocregion providers-3
|
// #enddocregion providers-3
|
||||||
})
|
})
|
||||||
export class ProviderComponent3 {
|
export class Provider3Component {
|
||||||
log: string;
|
log: string;
|
||||||
constructor(logger: Logger) {
|
constructor(logger: Logger) {
|
||||||
logger.log('Hello from logger provided with useClass:Logger');
|
logger.log('Hello from logger provided with useClass:Logger');
|
||||||
|
@ -57,7 +57,7 @@ class BetterLogger extends Logger {}
|
||||||
[{ provide: Logger, useClass: BetterLogger }]
|
[{ provide: Logger, useClass: BetterLogger }]
|
||||||
// #enddocregion providers-4
|
// #enddocregion providers-4
|
||||||
})
|
})
|
||||||
export class ProviderComponent4 {
|
export class Provider4Component {
|
||||||
log: string;
|
log: string;
|
||||||
constructor(logger: Logger) {
|
constructor(logger: Logger) {
|
||||||
logger.log('Hello from logger provided with useClass:BetterLogger');
|
logger.log('Hello from logger provided with useClass:BetterLogger');
|
||||||
|
@ -87,7 +87,7 @@ class EvenBetterLogger extends Logger {
|
||||||
{ provide: Logger, useClass: EvenBetterLogger }]
|
{ provide: Logger, useClass: EvenBetterLogger }]
|
||||||
// #enddocregion providers-5
|
// #enddocregion providers-5
|
||||||
})
|
})
|
||||||
export class ProviderComponent5 {
|
export class Provider5Component {
|
||||||
log: string;
|
log: string;
|
||||||
constructor(logger: Logger) {
|
constructor(logger: Logger) {
|
||||||
logger.log('Hello from EvenBetterlogger');
|
logger.log('Hello from EvenBetterlogger');
|
||||||
|
@ -114,7 +114,7 @@ class OldLogger {
|
||||||
{ provide: OldLogger, useClass: NewLogger}]
|
{ provide: OldLogger, useClass: NewLogger}]
|
||||||
// #enddocregion providers-6a
|
// #enddocregion providers-6a
|
||||||
})
|
})
|
||||||
export class ProviderComponent6a {
|
export class Provider6aComponent {
|
||||||
log: string;
|
log: string;
|
||||||
constructor(newLogger: NewLogger, oldLogger: OldLogger) {
|
constructor(newLogger: NewLogger, oldLogger: OldLogger) {
|
||||||
if (newLogger === oldLogger){
|
if (newLogger === oldLogger){
|
||||||
|
@ -137,7 +137,7 @@ export class ProviderComponent6a {
|
||||||
{ provide: OldLogger, useExisting: NewLogger}]
|
{ provide: OldLogger, useExisting: NewLogger}]
|
||||||
// #enddocregion providers-6b
|
// #enddocregion providers-6b
|
||||||
})
|
})
|
||||||
export class ProviderComponent6b {
|
export class Provider6bComponent {
|
||||||
log: string;
|
log: string;
|
||||||
constructor(newLogger: NewLogger, oldLogger: OldLogger) {
|
constructor(newLogger: NewLogger, oldLogger: OldLogger) {
|
||||||
if (newLogger !== oldLogger){
|
if (newLogger !== oldLogger){
|
||||||
|
@ -165,7 +165,7 @@ let silentLogger = {
|
||||||
[{ provide: Logger, useValue: silentLogger }]
|
[{ provide: Logger, useValue: silentLogger }]
|
||||||
// #enddocregion providers-7
|
// #enddocregion providers-7
|
||||||
})
|
})
|
||||||
export class ProviderComponent7 {
|
export class Provider7Component {
|
||||||
log: string;
|
log: string;
|
||||||
constructor(logger: Logger) {
|
constructor(logger: Logger) {
|
||||||
logger.log('Hello from logger provided with useValue');
|
logger.log('Hello from logger provided with useValue');
|
||||||
|
@ -179,13 +179,13 @@ export class ProviderComponent7 {
|
||||||
template: template,
|
template: template,
|
||||||
providers: [heroServiceProvider, Logger, UserService]
|
providers: [heroServiceProvider, Logger, UserService]
|
||||||
})
|
})
|
||||||
export class ProviderComponent8 {
|
export class Provider8Component {
|
||||||
|
// must be true else this component would have blown up at runtime
|
||||||
|
log = 'Hero service injected successfully via heroServiceProvider';
|
||||||
|
|
||||||
// #docregion provider-8-ctor
|
// #docregion provider-8-ctor
|
||||||
constructor(heroService: HeroService) { }
|
constructor(heroService: HeroService) { }
|
||||||
// #enddocregion provider-8-ctor
|
// #enddocregion provider-8-ctor
|
||||||
|
|
||||||
// must be true else this component would have blown up at runtime
|
|
||||||
log = 'Hero service injected successfully via heroServiceProvider';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////
|
/////////////////
|
||||||
|
@ -202,7 +202,7 @@ export class ProviderComponent8 {
|
||||||
providers: [{ provide: APP_CONFIG, useValue: HERO_DI_CONFIG }]
|
providers: [{ provide: APP_CONFIG, useValue: HERO_DI_CONFIG }]
|
||||||
// #enddocregion providers-9
|
// #enddocregion providers-9
|
||||||
})
|
})
|
||||||
export class ProviderComponent9 {
|
export class Provider9Component implements OnInit {
|
||||||
log: string;
|
log: string;
|
||||||
/*
|
/*
|
||||||
// #docregion provider-9-ctor-interface
|
// #docregion provider-9-ctor-interface
|
||||||
|
@ -225,13 +225,13 @@ export class ProviderComponent9 {
|
||||||
import { Optional } from '@angular/core';
|
import { Optional } from '@angular/core';
|
||||||
// #enddocregion import-optional
|
// #enddocregion import-optional
|
||||||
|
|
||||||
let some_message: string = 'Hello from the injected logger';
|
let some_message = 'Hello from the injected logger';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'provider-10',
|
selector: 'provider-10',
|
||||||
template: template
|
template: template
|
||||||
})
|
})
|
||||||
export class ProviderComponent10 {
|
export class Provider10Component implements OnInit {
|
||||||
log: string;
|
log: string;
|
||||||
// #docregion provider-10-ctor
|
// #docregion provider-10-ctor
|
||||||
constructor(@Optional() private logger: Logger) {
|
constructor(@Optional() private logger: Logger) {
|
||||||
|
@ -263,16 +263,16 @@ export class ProviderComponent10 {
|
||||||
<div id="p10"><provider-10></provider-10></div>
|
<div id="p10"><provider-10></provider-10></div>
|
||||||
`,
|
`,
|
||||||
directives: [
|
directives: [
|
||||||
ProviderComponent1,
|
Provider1Component,
|
||||||
ProviderComponent3,
|
Provider3Component,
|
||||||
ProviderComponent4,
|
Provider4Component,
|
||||||
ProviderComponent5,
|
Provider5Component,
|
||||||
ProviderComponent6a,
|
Provider6aComponent,
|
||||||
ProviderComponent6b,
|
Provider6bComponent,
|
||||||
ProviderComponent7,
|
Provider7Component,
|
||||||
ProviderComponent8,
|
Provider8Component,
|
||||||
ProviderComponent9,
|
Provider9Component,
|
||||||
ProviderComponent10,
|
Provider10Component,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class ProvidersComponent { }
|
export class ProvidersComponent { }
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { Component } from '@angular/core';
|
||||||
// Location of the template for this component
|
// Location of the template for this component
|
||||||
templateUrl: 'app/hello_world.html'
|
templateUrl: 'app/hello_world.html'
|
||||||
})
|
})
|
||||||
export class HelloWorld {
|
export class HelloWorldComponent {
|
||||||
|
|
||||||
// Declaring the variable for binding with initial value
|
// Declaring the variable for binding with initial value
|
||||||
yourName: string = '';
|
yourName: string = '';
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import { bootstrap } from '@angular/platform-browser-dynamic';
|
import { bootstrap } from '@angular/platform-browser-dynamic';
|
||||||
|
|
||||||
import { HelloWorld } from './hello_world';
|
import { HelloWorldComponent } from './hello_world';
|
||||||
|
|
||||||
bootstrap(HelloWorld);
|
bootstrap(HelloWorldComponent);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { UiTabs, UiPane } from './ui_tabs';
|
import { UiTabsComponent, UiPaneDirective } from './ui_tabs';
|
||||||
|
|
||||||
class Detail {
|
class Detail {
|
||||||
title: string;
|
title: string;
|
||||||
|
@ -13,23 +13,23 @@ class Detail {
|
||||||
template: `
|
template: `
|
||||||
<h4>Tabs Demo</h4>
|
<h4>Tabs Demo</h4>
|
||||||
<ui-tabs>
|
<ui-tabs>
|
||||||
<template ui-pane title='Overview' active="true">
|
<template uiPane title='Overview' active="true">
|
||||||
You have {{details.length}} details.
|
You have {{details.length}} details.
|
||||||
</template>
|
</template>
|
||||||
<template *ngFor="let detail of details" ui-pane [title]="detail.title">
|
<template *ngFor="let detail of details" uiPane [title]="detail.title">
|
||||||
{{detail.text}} <br><br>
|
{{detail.text}} <br><br>
|
||||||
<button class="btn" (click)="removeDetail(detail)">Remove</button>
|
<button class="btn" (click)="removeDetail(detail)">Remove</button>
|
||||||
</template>
|
</template>
|
||||||
<template ui-pane title='Summary'>
|
<template uiPane title='Summary'>
|
||||||
Next last ID is {{id}}.
|
Next last ID is {{id}}.
|
||||||
</template>
|
</template>
|
||||||
</ui-tabs>
|
</ui-tabs>
|
||||||
<hr>
|
<hr>
|
||||||
<button class="btn" (click)="addDetail()">Add Detail</button>
|
<button class="btn" (click)="addDetail()">Add Detail</button>
|
||||||
`,
|
`,
|
||||||
directives: [UiTabs, UiPane]
|
directives: [UiTabsComponent, UiPaneDirective]
|
||||||
})
|
})
|
||||||
export class DiDemo {
|
export class DiDemoComponent {
|
||||||
details: Detail[] = [];
|
details: Detail[] = [];
|
||||||
id: number = 0;
|
id: number = 0;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import { bootstrap } from '@angular/platform-browser-dynamic';
|
import { bootstrap } from '@angular/platform-browser-dynamic';
|
||||||
|
|
||||||
import { DiDemo } from './di_demo';
|
import { DiDemoComponent } from './di_demo';
|
||||||
|
|
||||||
bootstrap(DiDemo);
|
bootstrap(DiDemoComponent);
|
||||||
|
|
|
@ -3,9 +3,9 @@ import { Component, Directive, Input, QueryList,
|
||||||
ViewContainerRef, TemplateRef, ContentChildren } from '@angular/core';
|
ViewContainerRef, TemplateRef, ContentChildren } from '@angular/core';
|
||||||
|
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[ui-pane]'
|
selector: '[uiPane]'
|
||||||
})
|
})
|
||||||
export class UiPane {
|
export class UiPaneDirective {
|
||||||
@Input() title: string;
|
@Input() title: string;
|
||||||
private _active: boolean = false;
|
private _active: boolean = false;
|
||||||
|
|
||||||
|
@ -41,11 +41,11 @@ export class UiPane {
|
||||||
`,
|
`,
|
||||||
styles: ['a { cursor: pointer; cursor: hand; }']
|
styles: ['a { cursor: pointer; cursor: hand; }']
|
||||||
})
|
})
|
||||||
export class UiTabs {
|
export class UiTabsComponent {
|
||||||
@ContentChildren(UiPane) panes: QueryList<UiPane>;
|
@ContentChildren(UiPaneDirective) panes: QueryList<UiPaneDirective>;
|
||||||
|
|
||||||
select(pane: UiPane) {
|
select(pane: UiPaneDirective) {
|
||||||
this.panes.toArray().forEach((p: UiPane) => p.active = p === pane);
|
this.panes.toArray().forEach((p: UiPaneDirective) => p.active = p === pane);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import { bootstrap } from '@angular/platform-browser-dynamic';
|
import { bootstrap } from '@angular/platform-browser-dynamic';
|
||||||
|
|
||||||
import { TodoApp } from './todo_app';
|
import { TodoAppComponent } from './todo_app';
|
||||||
|
|
||||||
bootstrap(TodoApp);
|
bootstrap(TodoAppComponent);
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { Todo } from './todo';
|
import { Todo } from './todo';
|
||||||
import { TodoList } from './todo_list';
|
import { TodoListComponent } from './todo_list';
|
||||||
import { TodoForm } from './todo_form';
|
import { TodoFormComponent } from './todo_form';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'todo-app',
|
selector: 'todo-app',
|
||||||
|
@ -15,9 +15,9 @@ import { TodoForm } from './todo_form';
|
||||||
<todo-list [todos]="todos"></todo-list>
|
<todo-list [todos]="todos"></todo-list>
|
||||||
<todo-form (newTask)="addTask($event)"></todo-form>`,
|
<todo-form (newTask)="addTask($event)"></todo-form>`,
|
||||||
styles: ['a { cursor: pointer; cursor: hand; }'],
|
styles: ['a { cursor: pointer; cursor: hand; }'],
|
||||||
directives: [TodoList, TodoForm]
|
directives: [TodoListComponent, TodoFormComponent]
|
||||||
})
|
})
|
||||||
export class TodoApp {
|
export class TodoAppComponent {
|
||||||
todos: Todo[] = [
|
todos: Todo[] = [
|
||||||
{text: 'learn angular', done: true},
|
{text: 'learn angular', done: true},
|
||||||
{text: 'build an angular app', done: false}
|
{text: 'build an angular app', done: false}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import { Todo } from './todo';
|
||||||
<input class="btn-primary" type="submit" value="add">
|
<input class="btn-primary" type="submit" value="add">
|
||||||
</form>`
|
</form>`
|
||||||
})
|
})
|
||||||
export class TodoForm {
|
export class TodoFormComponent {
|
||||||
@Output() newTask = new EventEmitter<Todo>();
|
@Output() newTask = new EventEmitter<Todo>();
|
||||||
task: string = '';
|
task: string = '';
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,6 @@ import { Todo } from './todo';
|
||||||
</li>
|
</li>
|
||||||
</ul>`
|
</ul>`
|
||||||
})
|
})
|
||||||
export class TodoList {
|
export class TodoListComponent {
|
||||||
@Input() todos: Todo[];
|
@Input() todos: Todo[];
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {
|
||||||
OnChanges, SimpleChange,
|
OnChanges, SimpleChange,
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
|
|
||||||
import { Spy } from './spy.directive';
|
import { SpyDirective } from './spy.directive';
|
||||||
import { LoggerService } from './logger.service';
|
import { LoggerService } from './logger.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -18,9 +18,9 @@ import { LoggerService } from './logger.service';
|
||||||
</div>
|
</div>
|
||||||
`,
|
`,
|
||||||
styles: ['.counter {background: LightYellow; padding: 8px; margin-top: 8px}'],
|
styles: ['.counter {background: LightYellow; padding: 8px; margin-top: 8px}'],
|
||||||
directives: [Spy]
|
directives: [SpyDirective]
|
||||||
})
|
})
|
||||||
export class MyCounter implements OnChanges {
|
export class MyCounterComponent implements OnChanges {
|
||||||
@Input() counter: number;
|
@Input() counter: number;
|
||||||
changeLog: string[] = [];
|
changeLog: string[] = [];
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ export class MyCounter implements OnChanges {
|
||||||
</div>
|
</div>
|
||||||
`,
|
`,
|
||||||
styles: ['.parent {background: gold;}'],
|
styles: ['.parent {background: gold;}'],
|
||||||
directives: [MyCounter],
|
directives: [MyCounterComponent],
|
||||||
providers: [LoggerService]
|
providers: [LoggerService]
|
||||||
})
|
})
|
||||||
export class CounterParentComponent {
|
export class CounterParentComponent {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
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 { SpyDirective } from './spy.directive';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'spy-parent',
|
selector: 'spy-parent',
|
||||||
|
@ -11,7 +11,7 @@ import { Spy } from './spy.directive';
|
||||||
'.parent {background: khaki;}',
|
'.parent {background: khaki;}',
|
||||||
'.heroes {background: LightYellow; padding: 0 8px}'
|
'.heroes {background: LightYellow; padding: 0 8px}'
|
||||||
],
|
],
|
||||||
directives: [Spy],
|
directives: [SpyDirective],
|
||||||
providers: [LoggerService]
|
providers: [LoggerService]
|
||||||
})
|
})
|
||||||
export class SpyParentComponent {
|
export class SpyParentComponent {
|
||||||
|
|
|
@ -9,7 +9,7 @@ let nextId = 1;
|
||||||
// Spy on any element to which it is applied.
|
// Spy on any element to which it is applied.
|
||||||
// Usage: <div mySpy>...</div>
|
// Usage: <div mySpy>...</div>
|
||||||
@Directive({selector: '[mySpy]'})
|
@Directive({selector: '[mySpy]'})
|
||||||
export class Spy implements OnInit, OnDestroy {
|
export class SpyDirective implements OnInit, OnDestroy {
|
||||||
|
|
||||||
constructor(private logger: LoggerService) { }
|
constructor(private logger: LoggerService) { }
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,11 @@ import { HTTP_PROVIDERS } from '@angular/http';
|
||||||
import { FlyingHeroesComponent,
|
import { FlyingHeroesComponent,
|
||||||
FlyingHeroesImpureComponent } from './flying-heroes.component';
|
FlyingHeroesImpureComponent } from './flying-heroes.component';
|
||||||
import { HeroAsyncMessageComponent } from './hero-async-message.component';
|
import { HeroAsyncMessageComponent } from './hero-async-message.component';
|
||||||
import { HeroBirthday } from './hero-birthday1.component';
|
import { HeroBirthdayComponent } from './hero-birthday1.component';
|
||||||
import { HeroBirthday2 } from './hero-birthday2.component';
|
import { HeroBirthday2Component } from './hero-birthday2.component';
|
||||||
import { HeroListComponent } from './hero-list.component';
|
import { HeroListComponent } from './hero-list.component';
|
||||||
import { PowerBooster } from './power-booster.component';
|
import { PowerBoosterComponent } from './power-booster.component';
|
||||||
import { PowerBoostCalculator } from './power-boost-calculator.component';
|
import { PowerBoostCalculatorComponent } from './power-boost-calculator.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'my-app',
|
selector: 'my-app',
|
||||||
|
@ -17,10 +17,10 @@ import { PowerBoostCalculator } from './power-boost-calculator.component';
|
||||||
directives: [
|
directives: [
|
||||||
FlyingHeroesComponent, FlyingHeroesImpureComponent,
|
FlyingHeroesComponent, FlyingHeroesImpureComponent,
|
||||||
HeroAsyncMessageComponent,
|
HeroAsyncMessageComponent,
|
||||||
HeroBirthday,
|
HeroBirthdayComponent,
|
||||||
HeroBirthday2,
|
HeroBirthday2Component,
|
||||||
HeroListComponent,
|
HeroListComponent,
|
||||||
PowerBooster, PowerBoostCalculator
|
PowerBoosterComponent, PowerBoostCalculatorComponent
|
||||||
],
|
],
|
||||||
providers: [HTTP_PROVIDERS]
|
providers: [HTTP_PROVIDERS]
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* tslint:disable use-pipe-transform-interface */
|
||||||
// #docregion
|
// #docregion
|
||||||
// #docregion pure
|
// #docregion pure
|
||||||
import { Pipe, PipeTransform } from '@angular/core';
|
import { Pipe, PipeTransform } from '@angular/core';
|
||||||
|
|
|
@ -7,6 +7,6 @@ import { Component } from '@angular/core';
|
||||||
template: `<p>The hero's birthday is {{ birthday | date }}</p>`
|
template: `<p>The hero's birthday is {{ birthday | date }}</p>`
|
||||||
// #enddocregion hero-birthday-template
|
// #enddocregion hero-birthday-template
|
||||||
})
|
})
|
||||||
export class HeroBirthday {
|
export class HeroBirthdayComponent {
|
||||||
birthday = new Date(1988, 3, 15); // April 15, 1988
|
birthday = new Date(1988, 3, 15); // April 15, 1988
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import { Component } from '@angular/core';
|
||||||
// #enddocregion template
|
// #enddocregion template
|
||||||
})
|
})
|
||||||
// #docregion class
|
// #docregion class
|
||||||
export class HeroBirthday2 {
|
export class HeroBirthday2Component {
|
||||||
birthday = new Date(1988, 3, 15); // April 15, 1988
|
birthday = new Date(1988, 3, 15); // April 15, 1988
|
||||||
toggle = true; // start with true == shortDate
|
toggle = true; // start with true == shortDate
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ import { ExponentialStrengthPipe } from './exponential-strength.pipe';
|
||||||
`,
|
`,
|
||||||
pipes: [ExponentialStrengthPipe]
|
pipes: [ExponentialStrengthPipe]
|
||||||
})
|
})
|
||||||
export class PowerBoostCalculator {
|
export class PowerBoostCalculatorComponent {
|
||||||
power = 5;
|
power = 5;
|
||||||
factor = 1;
|
factor = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,4 +11,4 @@ import { ExponentialStrengthPipe } from './exponential-strength.pipe';
|
||||||
`,
|
`,
|
||||||
pipes: [ExponentialStrengthPipe]
|
pipes: [ExponentialStrengthPipe]
|
||||||
})
|
})
|
||||||
export class PowerBooster { }
|
export class PowerBoosterComponent { }
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
import { Component } from '@angular/core';
|
|
||||||
import { CanDeactivate, ComponentInstruction, Router } from '@angular/router-deprecated';
|
|
||||||
|
|
||||||
import { Crisis, CrisisService } from './crisis.service';
|
|
||||||
import { DialogService } from '../dialog.service';
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
template: `
|
|
||||||
<h2>"{{editName}}"</h2>
|
|
||||||
<div>
|
|
||||||
<label>Name: </label>
|
|
||||||
<input [(ngModel)]="editName" placeholder="name"/>
|
|
||||||
</div>
|
|
||||||
<button (click)="save()">Save</button>
|
|
||||||
<button (click)="cancel()">Cancel</button>
|
|
||||||
`,
|
|
||||||
styles: ['input {width: 20em}']
|
|
||||||
})
|
|
||||||
export class AddCrisisComponent implements CanDeactivate {
|
|
||||||
editName: string;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
private service: CrisisService,
|
|
||||||
private router: Router,
|
|
||||||
private dialog: DialogService) { }
|
|
||||||
|
|
||||||
routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
|
||||||
return !!this.editName.trim() ||
|
|
||||||
this.dialog.confirm('Discard changes?');
|
|
||||||
}
|
|
||||||
|
|
||||||
cancel() { this.gotoCrises(); }
|
|
||||||
|
|
||||||
save() {
|
|
||||||
this.service.addCrisis(this.editName);
|
|
||||||
this.gotoCrises();
|
|
||||||
}
|
|
||||||
|
|
||||||
gotoCrises() {
|
|
||||||
this.router.navigate(['CrisisCenter']);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -6,6 +6,15 @@ export class Crisis {
|
||||||
constructor(public id: number, public name: string) { }
|
constructor(public id: number, public name: string) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let crises = [
|
||||||
|
new Crisis(1, 'Dragon Burning Cities'),
|
||||||
|
new Crisis(2, 'Sky Rains Great White Sharks'),
|
||||||
|
new Crisis(3, 'Giant Asteroid Heading For Earth'),
|
||||||
|
new Crisis(4, 'Procrastinators Meeting Delayed Again'),
|
||||||
|
];
|
||||||
|
|
||||||
|
let crisesPromise = Promise.resolve(crises);
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CrisisService {
|
export class CrisisService {
|
||||||
getCrises() { return crisesPromise; }
|
getCrises() { return crisesPromise; }
|
||||||
|
@ -28,13 +37,4 @@ export class CrisisService {
|
||||||
}
|
}
|
||||||
// #docregion
|
// #docregion
|
||||||
}
|
}
|
||||||
|
|
||||||
let crises = [
|
|
||||||
new Crisis(1, 'Dragon Burning Cities'),
|
|
||||||
new Crisis(2, 'Sky Rains Great White Sharks'),
|
|
||||||
new Crisis(3, 'Giant Asteroid Heading For Earth'),
|
|
||||||
new Crisis(4, 'Procrastinators Meeting Delayed Again'),
|
|
||||||
];
|
|
||||||
|
|
||||||
let crisesPromise = Promise.resolve(crises);
|
|
||||||
// #enddocregion
|
// #enddocregion
|
||||||
|
|
|
@ -5,16 +5,6 @@ export class Hero {
|
||||||
constructor(public id: number, public name: string) { }
|
constructor(public id: number, public name: string) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class HeroService {
|
|
||||||
getHeroes() { return heroesPromise; }
|
|
||||||
|
|
||||||
getHero(id: number | string) {
|
|
||||||
return heroesPromise
|
|
||||||
.then(heroes => heroes.filter(h => h.id === +id)[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let HEROES = [
|
let HEROES = [
|
||||||
new Hero(11, 'Mr. Nice'),
|
new Hero(11, 'Mr. Nice'),
|
||||||
new Hero(12, 'Narco'),
|
new Hero(12, 'Narco'),
|
||||||
|
@ -25,3 +15,13 @@ let HEROES = [
|
||||||
];
|
];
|
||||||
|
|
||||||
let heroesPromise = Promise.resolve(HEROES);
|
let heroesPromise = Promise.resolve(HEROES);
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class HeroService {
|
||||||
|
getHeroes() { return heroesPromise; }
|
||||||
|
|
||||||
|
getHero(id: number | string) {
|
||||||
|
return heroesPromise
|
||||||
|
.then(heroes => heroes.filter(h => h.id === +id)[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
/* tslint:disable:member-ordering */
|
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { JSONP_PROVIDERS } from '@angular/http';
|
import { JSONP_PROVIDERS } from '@angular/http';
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* tslint:disable:member-ordering forin */
|
/* tslint:disable forin */
|
||||||
// #docplaster
|
// #docplaster
|
||||||
|
|
||||||
import { AfterViewInit, Component, ElementRef, OnInit, QueryList, ViewChildren } from '@angular/core';
|
import { AfterViewInit, Component, ElementRef, OnInit, QueryList, ViewChildren } from '@angular/core';
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
// Useful for spying on an element
|
|
||||||
// for fun; not used (yet)
|
|
||||||
import { Directive, ElementRef } from '@angular/core';
|
|
||||||
|
|
||||||
// set the selector for the element type to spy on.
|
|
||||||
@Directive({selector: 'select'})
|
|
||||||
export class DecoratorDirective {
|
|
||||||
constructor(el: ElementRef) {
|
|
||||||
console.log(el);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +1,9 @@
|
||||||
|
/* tslint:disable use-input-property-decorator use-output-property-decorator */
|
||||||
// #docplaster
|
// #docplaster
|
||||||
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
||||||
|
|
||||||
import { Hero } from './hero';
|
import { Hero } from './hero';
|
||||||
|
|
||||||
let nextHeroDetailId = 1;
|
|
||||||
|
|
||||||
// #docregion input-output-2
|
// #docregion input-output-2
|
||||||
@Component({
|
@Component({
|
||||||
// #enddocregion input-output-2
|
// #enddocregion input-output-2
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* tslint:disable use-output-property-decorator */
|
||||||
// #docplaster
|
// #docplaster
|
||||||
import { Directive, ElementRef, EventEmitter, Output } from '@angular/core';
|
import { Directive, ElementRef, EventEmitter, Output } from '@angular/core';
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,21 @@ export class Hero {
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #docregion hero-array
|
||||||
|
const HEROES: Hero[] = [
|
||||||
|
{ id: 11, name: 'Mr. Nice' },
|
||||||
|
{ id: 12, name: 'Narco' },
|
||||||
|
{ id: 13, name: 'Bombasto' },
|
||||||
|
{ id: 14, name: 'Celeritas' },
|
||||||
|
{ id: 15, name: 'Magneta' },
|
||||||
|
{ id: 16, name: 'RubberMan' },
|
||||||
|
{ id: 17, name: 'Dynama' },
|
||||||
|
{ id: 18, name: 'Dr IQ' },
|
||||||
|
{ id: 19, name: 'Magma' },
|
||||||
|
{ id: 20, name: 'Tornado' }
|
||||||
|
];
|
||||||
|
// #enddocregion hero-array
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'my-app',
|
selector: 'my-app',
|
||||||
template: `
|
template: `
|
||||||
|
@ -90,21 +105,5 @@ export class AppComponent {
|
||||||
onSelect(hero: Hero) { this.selectedHero = hero; }
|
onSelect(hero: Hero) { this.selectedHero = hero; }
|
||||||
// #enddocregion on-select-1
|
// #enddocregion on-select-1
|
||||||
}
|
}
|
||||||
// #enddocregion pt2
|
|
||||||
|
|
||||||
// #docregion hero-array
|
|
||||||
const HEROES: Hero[] = [
|
|
||||||
{ id: 11, name: 'Mr. Nice' },
|
|
||||||
{ id: 12, name: 'Narco' },
|
|
||||||
{ id: 13, name: 'Bombasto' },
|
|
||||||
{ id: 14, name: 'Celeritas' },
|
|
||||||
{ id: 15, name: 'Magneta' },
|
|
||||||
{ id: 16, name: 'RubberMan' },
|
|
||||||
{ id: 17, name: 'Dynama' },
|
|
||||||
{ id: 18, name: 'Dr IQ' },
|
|
||||||
{ id: 19, name: 'Magma' },
|
|
||||||
{ id: 20, name: 'Tornado' }
|
|
||||||
];
|
|
||||||
// #enddocregion hero-array
|
|
||||||
|
|
||||||
// #enddocregion pt2
|
// #enddocregion pt2
|
||||||
|
|
|
@ -8,6 +8,19 @@ import { Hero } from './hero';
|
||||||
import { HeroDetailComponent } from './hero-detail.component';
|
import { HeroDetailComponent } from './hero-detail.component';
|
||||||
// #enddocregion hero-detail-import
|
// #enddocregion hero-detail-import
|
||||||
|
|
||||||
|
const HEROES: Hero[] = [
|
||||||
|
{ id: 11, name: 'Mr. Nice' },
|
||||||
|
{ id: 12, name: 'Narco' },
|
||||||
|
{ id: 13, name: 'Bombasto' },
|
||||||
|
{ id: 14, name: 'Celeritas' },
|
||||||
|
{ id: 15, name: 'Magneta' },
|
||||||
|
{ id: 16, name: 'RubberMan' },
|
||||||
|
{ id: 17, name: 'Dynama' },
|
||||||
|
{ id: 18, name: 'Dr IQ' },
|
||||||
|
{ id: 19, name: 'Magma' },
|
||||||
|
{ id: 20, name: 'Tornado' }
|
||||||
|
];
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'my-app',
|
selector: 'my-app',
|
||||||
// #docregion hero-detail-template
|
// #docregion hero-detail-template
|
||||||
|
@ -84,16 +97,3 @@ export class AppComponent {
|
||||||
|
|
||||||
onSelect(hero: Hero) { this.selectedHero = hero; }
|
onSelect(hero: Hero) { this.selectedHero = hero; }
|
||||||
}
|
}
|
||||||
|
|
||||||
const HEROES: Hero[] = [
|
|
||||||
{ id: 11, name: 'Mr. Nice' },
|
|
||||||
{ id: 12, name: 'Narco' },
|
|
||||||
{ id: 13, name: 'Bombasto' },
|
|
||||||
{ id: 14, name: 'Celeritas' },
|
|
||||||
{ id: 15, name: 'Magneta' },
|
|
||||||
{ id: 16, name: 'RubberMan' },
|
|
||||||
{ id: 17, name: 'Dynama' },
|
|
||||||
{ id: 18, name: 'Dr IQ' },
|
|
||||||
{ id: 19, name: 'Magma' },
|
|
||||||
{ id: 20, name: 'Tornado' }
|
|
||||||
];
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* tslint:disable no-unused-variables */
|
||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion
|
// #docregion
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import { UpgradeAdapter } from '@angular/upgrade';
|
|
||||||
import { ContainerComponent } from './container.component';
|
import { ContainerComponent } from './container.component';
|
||||||
import { heroDetailComponent } from './hero-detail.component';
|
import { heroDetailComponent } from './hero-detail.component';
|
||||||
import { upgradeAdapter } from './upgrade_adapter';
|
import { upgradeAdapter } from './upgrade_adapter';
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { ClickMeComponent } from './click-me.component';
|
import { ClickMeComponent } from './click-me.component';
|
||||||
import { ClickMeComponent2 } from './click-me2.component';
|
import { ClickMe2Component } from './click-me2.component';
|
||||||
|
|
||||||
import { LoopbackComponent } from './loop-back.component';
|
import { LoopbackComponent } from './loop-back.component';
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ import { LittleTourComponent } from './little-tour.component';
|
||||||
selector: 'my-app',
|
selector: 'my-app',
|
||||||
templateUrl: 'app/app.component.html',
|
templateUrl: 'app/app.component.html',
|
||||||
directives: [
|
directives: [
|
||||||
ClickMeComponent, ClickMeComponent2,
|
ClickMeComponent, ClickMe2Component,
|
||||||
LoopbackComponent,
|
LoopbackComponent,
|
||||||
KeyUpComponent_v1, KeyUpComponent_v2, KeyUpComponent_v3, KeyUpComponent_v4,
|
KeyUpComponent_v1, KeyUpComponent_v2, KeyUpComponent_v3, KeyUpComponent_v4,
|
||||||
LittleTourComponent
|
LittleTourComponent
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { Component } from '@angular/core';
|
||||||
<button (click)="onClickMe2($event)">No! .. Click me!</button>
|
<button (click)="onClickMe2($event)">No! .. Click me!</button>
|
||||||
{{clickMessage}}`
|
{{clickMessage}}`
|
||||||
})
|
})
|
||||||
export class ClickMeComponent2 {
|
export class ClickMe2Component {
|
||||||
clickMessage = '';
|
clickMessage = '';
|
||||||
clicks = 1;
|
clicks = 1;
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ include ../_util-fns
|
||||||
Now that we have defined the complete model we are ready to create components to represent the dynamic form.
|
Now that we have defined the complete model we are ready to create components to represent the dynamic form.
|
||||||
|
|
||||||
:marked
|
:marked
|
||||||
`DynamicForm` is the entry point and the main container for the form.
|
`DynamicFormComponent` is the entry point and the main container for the form.
|
||||||
+makeTabs(
|
+makeTabs(
|
||||||
`cb-dynamic-form/ts/app/dynamic-form.component.html,
|
`cb-dynamic-form/ts/app/dynamic-form.component.html,
|
||||||
cb-dynamic-form/ts/app/dynamic-form.component.ts`,
|
cb-dynamic-form/ts/app/dynamic-form.component.ts`,
|
||||||
|
@ -101,7 +101,7 @@ include ../_util-fns
|
||||||
:marked
|
:marked
|
||||||
## Questionnaire data
|
## Questionnaire data
|
||||||
:marked
|
:marked
|
||||||
`DynamicForm` expects the list of questions in the form of an array bound to `@Input() questions`.
|
`DynamicFormComponent` expects the list of questions in the form of an array bound to `@Input() questions`.
|
||||||
|
|
||||||
The set of questions we have defined for the job application is returned from the `QuestionService`.
|
The set of questions we have defined for the job application is returned from the `QuestionService`.
|
||||||
In a real app we'd retrieve these questions from storage.
|
In a real app we'd retrieve these questions from storage.
|
||||||
|
@ -140,4 +140,4 @@ figure.image-display
|
||||||
|
|
||||||
|
|
||||||
:marked
|
:marked
|
||||||
[Back to top](#top)
|
[Back to top](#top)
|
||||||
|
|
|
@ -167,17 +167,15 @@ a#respond-to-user
|
||||||
|
|
||||||
We'll need to
|
We'll need to
|
||||||
1. detect when the user hovers into and out of the element,
|
1. detect when the user hovers into and out of the element,
|
||||||
1. respond to those actions by setting and clearing the highlight color, respectively.
|
2. respond to those actions by setting and clearing the highlight color, respectively.
|
||||||
|
|
||||||
Let's start with event detection.
|
We use the `@HostListener` decorator on a method which is called when the event is raised.
|
||||||
Add a `host` property to the directive metadata and give it a configuration object
|
|
||||||
that specifies two mouse events and the directive methods to call when they are raised:
|
|
||||||
|
|
||||||
+makeExample('attribute-directives/ts/app/highlight.directive.2.ts','host')(format=".")
|
+makeExample('attribute-directives/ts/app/highlight.directive.2.ts','host')(format=".")
|
||||||
|
|
||||||
.l-sub-section
|
.l-sub-section
|
||||||
:marked
|
:marked
|
||||||
The `host` property refers to the DOM element that hosts our attribute directive, the `<p>` in our case.
|
The `@HostListener` decorator refers to the DOM element that hosts our attribute directive, the `<p>` in our case.
|
||||||
|
|
||||||
We could have attached event listeners by manipulating the host DOM element directly, but
|
We could have attached event listeners by manipulating the host DOM element directly, but
|
||||||
there are at least three problems with such an approach:
|
there are at least three problems with such an approach:
|
||||||
|
@ -186,7 +184,7 @@ a#respond-to-user
|
||||||
1. We must *detach* our listener when the directive is destroyed to avoid memory leaks.
|
1. We must *detach* our listener when the directive is destroyed to avoid memory leaks.
|
||||||
1. We'd be talking to DOM API directly which, we learned, is something to avoid.
|
1. We'd be talking to DOM API directly which, we learned, is something to avoid.
|
||||||
|
|
||||||
Let's roll with the `host` property.
|
Let's roll with the `@HostListener` decorator.
|
||||||
:marked
|
:marked
|
||||||
Now we implement the two mouse event handlers:
|
Now we implement the two mouse event handlers:
|
||||||
+makeExample('attribute-directives/ts/app/highlight.directive.2.ts','mouse-methods')(format=".")
|
+makeExample('attribute-directives/ts/app/highlight.directive.2.ts','mouse-methods')(format=".")
|
||||||
|
|
|
@ -19,11 +19,6 @@
|
||||||
140
|
140
|
||||||
],
|
],
|
||||||
"member-access": false,
|
"member-access": false,
|
||||||
"member-ordering": [
|
|
||||||
true,
|
|
||||||
"static-before-instance",
|
|
||||||
"variables-before-functions"
|
|
||||||
],
|
|
||||||
"no-arg": true,
|
"no-arg": true,
|
||||||
"no-bitwise": true,
|
"no-bitwise": true,
|
||||||
"no-console": [
|
"no-console": [
|
||||||
|
@ -41,7 +36,6 @@
|
||||||
"no-empty": false,
|
"no-empty": false,
|
||||||
"no-eval": true,
|
"no-eval": true,
|
||||||
"no-inferrable-types": true,
|
"no-inferrable-types": true,
|
||||||
"no-shadowed-variable": true,
|
|
||||||
"no-string-literal": false,
|
"no-string-literal": false,
|
||||||
"no-switch-case-fall-through": true,
|
"no-switch-case-fall-through": true,
|
||||||
"no-trailing-whitespace": true,
|
"no-trailing-whitespace": true,
|
||||||
|
@ -97,8 +91,6 @@
|
||||||
"use-input-property-decorator": true,
|
"use-input-property-decorator": true,
|
||||||
"use-output-property-decorator": true,
|
"use-output-property-decorator": true,
|
||||||
"use-host-property-decorator": true,
|
"use-host-property-decorator": true,
|
||||||
"no-input-rename": true,
|
|
||||||
"no-output-rename": true,
|
|
||||||
"use-life-cycle-interface": true,
|
"use-life-cycle-interface": true,
|
||||||
"use-pipe-transform-interface": true,
|
"use-pipe-transform-interface": true,
|
||||||
"component-class-suffix": true,
|
"component-class-suffix": true,
|
||||||
|
|
Loading…
Reference in New Issue