refactor(lifecycle): prefix lifecycle methods with "ng"

BREAKING CHANGE:
Previously, components that would implement lifecycle interfaces would include methods
like "onChanges" or "afterViewInit." Given that components were at risk of using such
names without realizing that Angular would call the methods at different points of
the component lifecycle. This change adds an "ng" prefix to all lifecycle hook methods,
far reducing the risk of an accidental name collision.

To fix, just rename these methods:
 * onInit
 * onDestroy
 * doCheck
 * onChanges
 * afterContentInit
 * afterContentChecked
 * afterViewInit
 * afterViewChecked
 * _Router Hooks_
 * onActivate
 * onReuse
 * onDeactivate
 * canReuse
 * canDeactivate

To:
 * ngOnInit,
 * ngOnDestroy,
 * ngDoCheck,
 * ngOnChanges,
 * ngAfterContentInit,
 * ngAfterContentChecked,
 * ngAfterViewInit,
 * ngAfterViewChecked
 * _Router Hooks_
 * routerOnActivate
 * routerOnReuse
 * routerOnDeactivate
 * routerCanReuse
 * routerCanDeactivate

The names of lifecycle interfaces and enums have not changed, though interfaces
have been updated to reflect the new method names.

Closes #5036
This commit is contained in:
Jeff Cross
2015-11-16 17:04:36 -08:00
committed by vsavkin
parent 4215afc639
commit 604c8bbad5
63 changed files with 618 additions and 583 deletions

View File

@ -194,7 +194,7 @@ export class QueryMetadata extends DependencyMetadata {
/**
* Configures a content query.
*
* Content queries are set before the `afterContentInit` callback is called.
* Content queries are set before the `ngAfterContentInit` callback is called.
*
* ### Example
*
@ -205,7 +205,7 @@ export class QueryMetadata extends DependencyMetadata {
* class SomeDir {
* @ContentChildren(ChildDirective) contentChildren: QueryList<ChildDirective>;
*
* afterContentInit() {
* ngAfterContentInit() {
* // contentChildren is set
* }
* }
@ -222,7 +222,7 @@ export class ContentChildrenMetadata extends QueryMetadata {
/**
* Configures a content query.
*
* Content queries are set before the `afterContentInit` callback is called.
* Content queries are set before the `ngAfterContentInit` callback is called.
*
* ### Example
*
@ -233,7 +233,7 @@ export class ContentChildrenMetadata extends QueryMetadata {
* class SomeDir {
* @ContentChild(ChildDirective) contentChild;
*
* afterContentInit() {
* ngAfterContentInit() {
* // contentChild is set
* }
* }
@ -296,7 +296,7 @@ export class ViewQueryMetadata extends QueryMetadata {
/**
* Configures a view query.
*
* View queries are set before the `afterViewInit` callback is called.
* View queries are set before the `ngAfterViewInit` callback is called.
*
* ### Example
*
@ -309,7 +309,7 @@ export class ViewQueryMetadata extends QueryMetadata {
* class SomeDir {
* @ViewChildren(ItemDirective) viewChildren: QueryList<ItemDirective>;
*
* afterViewInit() {
* ngAfterViewInit() {
* // viewChildren is set
* }
* }
@ -323,7 +323,7 @@ export class ViewChildrenMetadata extends ViewQueryMetadata {
/**
* Configures a view query.
*
* View queries are set before the `afterViewInit` callback is called.
* View queries are set before the `ngAfterViewInit` callback is called.
*
* ### Example
*
@ -336,7 +336,7 @@ export class ViewChildrenMetadata extends ViewQueryMetadata {
* class SomeDir {
* @ViewChild(ItemDirective) viewChild:ItemDirective;
*
* afterViewInit() {
* ngAfterViewInit() {
* // viewChild is set
* }
* }

View File

@ -720,8 +720,8 @@ export class DirectiveMetadata extends InjectableMetadata {
/**
* Configures the queries that will be injected into the directive.
*
* Content queries are set before the `afterContentInit` callback is called.
* View queries are set before the `afterViewInit` callback is called.
* Content queries are set before the `ngAfterContentInit` callback is called.
* View queries are set before the `ngAfterViewInit` callback is called.
*
* ### Example
*
@ -739,11 +739,11 @@ export class DirectiveMetadata extends InjectableMetadata {
* contentChildren: QueryList<ChildDirective>,
* viewChildren: QueryList<ChildDirective>
*
* afterContentInit() {
* ngAfterContentInit() {
* // contentChildren is set
* }
*
* afterViewInit() {
* ngAfterViewInit() {
* // viewChildren is set
* }
* }