OnDestroy

Stable Class What it does Lifecycle hook that is called when a directive or pipe is destroyed. How to use . @Component({selector: 'my-cmp', template: `...`}) class MyComponent implements OnDestroy { ngOnDestroy() { // ... } } Class Overview class OnDestroy { ngOnDestroy() : void } Class Description ngOnDestroy callback is typically used for any custom cleanup that needs to occur when the instance is destroyed. See Lifecycle Hooks Guide. Class Details ngOnDestroy() : void

Route

Stable Interface Interface Overview interface Route { path : string pathMatch : string component : Type<any> redirectTo : string outlet : string canActivate : any[] canActivateChild : any[] canDeactivate : any[] canLoad : any[] data : Data resolve : ResolveData children : Route[] loadChildren : LoadChildren } Interface Description See Routes for more details. Interface Details path : string pathMatch : string component : Type<any> redirectTo : str

Testing

Techniques and practices for testing an Angular 2 app This chapter offers tips and techniques for testing Angular applications. Along the way you will learn some general testing principles and techniques but the focus is on Angular testing. Contents Introduction to Angular Testing Setup The first karma test The Angular Testing Platform (ATP) The sample application and its tests A simple component test Test a component with a service dependency Test a component with an async service Test a comp

SpyLocation

Experimental Class Class Overview class SpyLocation { urlChanges : string[] setInitialPath(url: string) setBaseHref(url: string) path() : string isCurrentPathEqualTo(path: string, query?: string) : boolean simulateUrlPop(pathname: string) simulateHashChange(pathname: string) prepareExternalUrl(url: string) : string go(path: string, query?: string) replaceState(path: string, query?: string) forward() back() subscribe(onNext: (value: any) => void, onThrow?: (error:

MinLengthValidator

Stable Directive Class Overview class MinLengthValidator { minlength : string ngOnChanges(changes: SimpleChanges) validate(c: AbstractControl) : {[key: string]: any} registerOnValidatorChange(fn: () => void) } Selectors [minlength][formControlName] [minlength][formControl] [minlength][ngModel] Class Description A directive which installs the MinLengthValidator for any formControlName, formControl, or control with ngModel that also has a minlength attribute. Class Details min

SafeScript

Stable Interface Interface Overview interface SafeScript { } Interface Description Marker interface for a value that's safe to use as JavaScript. exported from @angular/platform-browser/index, defined in @angular/platform-browser/src/security/dom_sanitization_service.ts

OnInit

Stable Class What it does Lifecycle hook that is called after data-bound properties of a directive are initialized. How to use . @Component({selector: 'my-cmp', template: `...`}) class MyComponent implements OnInit { ngOnInit() { // ... } } Class Overview class OnInit { ngOnInit() : void } Class Description ngOnInit is called right after the directive's data-bound properties have been checked for the first time, and before any of its children have been checked. It is invoked

Component Interaction

Share information between different directives and components This cookbook contains recipes for common component communication scenarios in which two or more components share information. Table of contents Pass data from parent to child with input binding Intercept input property changes with a setter Intercept input property changes with ngOnChanges Parent listens for child event Parent interacts with child via a local variable Parent calls a ViewChild Parent and children communicate via a se

Validators

Stable Class Class Overview class Validators { staticrequired(control: AbstractControl) : {[key: string]: boolean} staticminLength(minLength: number) : ValidatorFn staticmaxLength(maxLength: number) : ValidatorFn staticpattern(pattern: string) : ValidatorFn staticnullValidator(c: AbstractControl) : {[key: string]: boolean} staticcompose(validators: ValidatorFn[]) : ValidatorFn staticcomposeAsync(validators: AsyncValidatorFn[]) : AsyncValidatorFn } Class Description Provides a

NG_ASYNC_VALIDATORS

Stable Const Variable Export export NG_ASYNC_VALIDATORS Providers for asynchronous validators to be used for FormControls in a form. Provide this using multi: true to add validators. See NG_VALIDATORS for more details. exported from @angular/forms/index defined in @angular/forms/src/validators.ts