2016-06-23 12:47:54 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2016-04-28 20:50:03 -04:00
|
|
|
import {SimpleChange} from '../change_detection/change_detection_util';
|
2015-05-22 16:14:59 -04:00
|
|
|
|
2015-09-11 17:23:24 -04:00
|
|
|
|
2016-05-09 18:45:04 -04:00
|
|
|
/**
|
|
|
|
* A `changes` object whose keys are property names and
|
|
|
|
* values are instances of {@link SimpleChange}. See {@link OnChanges}
|
2018-04-05 17:31:44 -04:00
|
|
|
*
|
2016-05-09 18:45:04 -04:00
|
|
|
*/
|
2016-06-08 19:38:52 -04:00
|
|
|
export interface SimpleChanges { [propName: string]: SimpleChange; }
|
2016-05-09 18:45:04 -04:00
|
|
|
|
2015-05-22 16:14:59 -04:00
|
|
|
/**
|
2018-04-05 04:58:02 -04:00
|
|
|
* @usageNotes
|
2016-09-14 12:42:41 -04:00
|
|
|
* {@example core/ts/metadata/lifecycle_hooks_spec.ts region='OnChanges'}
|
2015-08-31 21:32:32 -04:00
|
|
|
*
|
2016-09-14 12:42:41 -04:00
|
|
|
* @description
|
2018-04-05 05:16:31 -04:00
|
|
|
* Lifecycle hook that is called when any data-bound property of a directive changes.
|
|
|
|
*
|
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
2015-11-16 20:04:36 -05:00
|
|
|
* `ngOnChanges` is called right after the data-bound properties have been checked and before view
|
2015-09-24 18:40:50 -04:00
|
|
|
* and content children are checked if at least one of them has changed.
|
2016-09-14 12:42:41 -04:00
|
|
|
* The `changes` parameter contains the changed properties.
|
2015-08-31 21:32:32 -04:00
|
|
|
*
|
2018-05-18 07:19:29 -04:00
|
|
|
* See ["Lifecycle Hooks Guide"](guide/lifecycle-hooks#onchanges).
|
2015-09-24 18:40:50 -04:00
|
|
|
*
|
2018-04-05 17:31:44 -04:00
|
|
|
*
|
2015-05-27 11:07:37 -04:00
|
|
|
*/
|
2017-02-23 21:04:51 -05:00
|
|
|
export interface OnChanges { ngOnChanges(changes: SimpleChanges): void; }
|
2015-05-27 11:07:37 -04:00
|
|
|
|
2015-05-27 13:14:37 -04:00
|
|
|
/**
|
2018-04-05 04:58:02 -04:00
|
|
|
* @usageNotes
|
2016-09-14 12:42:41 -04:00
|
|
|
* {@example core/ts/metadata/lifecycle_hooks_spec.ts region='OnInit'}
|
2015-08-31 21:32:32 -04:00
|
|
|
*
|
2016-09-14 12:42:41 -04:00
|
|
|
* @description
|
2018-04-05 05:16:31 -04:00
|
|
|
* Lifecycle hook that is called after data-bound properties of a directive are
|
|
|
|
* initialized.
|
|
|
|
*
|
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
2015-11-16 20:04:36 -05:00
|
|
|
* `ngOnInit` is called right after the directive's data-bound properties have been checked for the
|
2015-09-24 18:40:50 -04:00
|
|
|
* first time, and before any of its children have been checked. It is invoked only once when the
|
|
|
|
* directive is instantiated.
|
2015-08-31 21:32:32 -04:00
|
|
|
*
|
2018-05-18 07:19:29 -04:00
|
|
|
* See ["Lifecycle Hooks Guide"](guide/lifecycle-hooks).
|
2015-09-24 18:40:50 -04:00
|
|
|
*
|
2018-04-05 17:31:44 -04:00
|
|
|
*
|
2015-05-27 13:14:37 -04:00
|
|
|
*/
|
2017-02-23 21:04:51 -05:00
|
|
|
export interface OnInit { ngOnInit(): void; }
|
2015-05-27 13:14:37 -04:00
|
|
|
|
|
|
|
/**
|
2018-04-05 04:58:02 -04:00
|
|
|
* @usageNotes
|
2016-09-14 12:42:41 -04:00
|
|
|
* {@example core/ts/metadata/lifecycle_hooks_spec.ts region='DoCheck'}
|
2015-08-31 21:32:32 -04:00
|
|
|
*
|
2016-09-14 12:42:41 -04:00
|
|
|
* @description
|
2018-04-05 05:16:31 -04:00
|
|
|
* Lifecycle hook that is called when Angular dirty checks a directive.
|
|
|
|
*
|
2016-06-08 19:38:52 -04:00
|
|
|
* `ngDoCheck` gets called to check the changes in the directives in addition to the default
|
2016-09-14 12:42:41 -04:00
|
|
|
* algorithm. The default change detection algorithm looks for differences by comparing
|
|
|
|
* bound-property values by reference across change detection runs.
|
2015-08-31 21:32:32 -04:00
|
|
|
*
|
2016-05-26 13:27:42 -04:00
|
|
|
* Note that a directive typically should not use both `DoCheck` and {@link OnChanges} to respond to
|
2016-09-14 12:42:41 -04:00
|
|
|
* changes on the same input, as `ngOnChanges` will continue to be called when the default change
|
|
|
|
* detector detects changes.
|
2015-09-24 18:40:50 -04:00
|
|
|
*
|
2016-09-14 12:42:41 -04:00
|
|
|
* See {@link KeyValueDiffers} and {@link IterableDiffers} for implementing custom dirty checking
|
|
|
|
* for collections.
|
2015-09-24 18:40:50 -04:00
|
|
|
*
|
2018-05-18 07:19:29 -04:00
|
|
|
* See ["Lifecycle Hooks Guide"](guide/lifecycle-hooks#docheck).
|
2015-09-24 18:40:50 -04:00
|
|
|
*
|
2018-04-05 17:31:44 -04:00
|
|
|
*
|
2015-05-27 13:14:37 -04:00
|
|
|
*/
|
2017-02-23 21:04:51 -05:00
|
|
|
export interface DoCheck { ngDoCheck(): void; }
|
2015-05-27 13:14:37 -04:00
|
|
|
|
2015-08-28 21:11:04 -04:00
|
|
|
/**
|
2018-04-05 04:58:02 -04:00
|
|
|
* @usageNotes
|
2016-09-14 12:42:41 -04:00
|
|
|
* {@example core/ts/metadata/lifecycle_hooks_spec.ts region='OnDestroy'}
|
2015-08-31 21:32:32 -04:00
|
|
|
*
|
2016-09-14 12:42:41 -04:00
|
|
|
* @description
|
2018-04-05 05:16:31 -04:00
|
|
|
* Lifecycle hook that is called when a directive, pipe or service is destroyed.
|
|
|
|
*
|
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
2015-11-16 20:04:36 -05:00
|
|
|
* `ngOnDestroy` callback is typically used for any custom cleanup that needs to occur when the
|
2016-09-14 12:42:41 -04:00
|
|
|
* instance is destroyed.
|
2015-11-17 13:09:23 -05:00
|
|
|
*
|
2018-05-18 07:19:29 -04:00
|
|
|
* See ["Lifecycle Hooks Guide"](guide/lifecycle-hooks).
|
2015-11-17 13:09:23 -05:00
|
|
|
*
|
2018-04-05 17:31:44 -04:00
|
|
|
*
|
2015-08-28 21:11:04 -04:00
|
|
|
*/
|
2017-02-23 21:04:51 -05:00
|
|
|
export interface OnDestroy { ngOnDestroy(): void; }
|
2015-08-28 21:11:04 -04:00
|
|
|
|
2015-05-27 11:07:37 -04:00
|
|
|
/**
|
2015-09-24 18:40:50 -04:00
|
|
|
*
|
2018-04-05 04:58:02 -04:00
|
|
|
* @usageNotes
|
2016-09-14 12:42:41 -04:00
|
|
|
* {@example core/ts/metadata/lifecycle_hooks_spec.ts region='AfterContentInit'}
|
2015-09-24 18:40:50 -04:00
|
|
|
*
|
2016-09-14 12:42:41 -04:00
|
|
|
* @description
|
2018-04-05 05:16:31 -04:00
|
|
|
* Lifecycle hook that is called after a directive's content has been fully
|
|
|
|
* initialized.
|
|
|
|
*
|
2018-05-18 07:19:29 -04:00
|
|
|
* See ["Lifecycle Hooks Guide"](guide/lifecycle-hooks#aftercontent).
|
2015-09-24 18:40:50 -04:00
|
|
|
*
|
2018-04-05 17:31:44 -04:00
|
|
|
*
|
2015-05-27 11:07:37 -04:00
|
|
|
*/
|
2017-02-23 21:04:51 -05:00
|
|
|
export interface AfterContentInit { ngAfterContentInit(): void; }
|
2015-08-28 21:11:04 -04:00
|
|
|
|
|
|
|
/**
|
2018-04-05 04:58:02 -04:00
|
|
|
* @usageNotes
|
2016-09-14 12:42:41 -04:00
|
|
|
* {@example core/ts/metadata/lifecycle_hooks_spec.ts region='AfterContentChecked'}
|
2015-09-24 18:40:50 -04:00
|
|
|
*
|
2016-09-14 12:42:41 -04:00
|
|
|
* @description
|
2018-04-05 05:16:31 -04:00
|
|
|
* Lifecycle hook that is called after every check of a directive's content.
|
|
|
|
*
|
2018-05-18 07:19:29 -04:00
|
|
|
* See ["Lifecycle Hooks Guide"](guide/lifecycle-hooks#aftercontent).
|
2015-09-24 18:40:50 -04:00
|
|
|
*
|
2018-04-05 17:31:44 -04:00
|
|
|
*
|
2015-08-28 21:11:04 -04:00
|
|
|
*/
|
2017-02-23 21:04:51 -05:00
|
|
|
export interface AfterContentChecked { ngAfterContentChecked(): void; }
|
2015-08-28 21:11:04 -04:00
|
|
|
|
|
|
|
/**
|
2018-04-05 04:58:02 -04:00
|
|
|
* @usageNotes
|
2016-09-14 12:42:41 -04:00
|
|
|
* {@example core/ts/metadata/lifecycle_hooks_spec.ts region='AfterViewInit'}
|
2015-09-24 18:40:50 -04:00
|
|
|
*
|
2016-09-14 12:42:41 -04:00
|
|
|
* @description
|
2018-04-05 05:16:31 -04:00
|
|
|
* Lifecycle hook that is called after a component's view has been fully
|
|
|
|
* initialized.
|
|
|
|
*
|
2018-05-18 07:19:29 -04:00
|
|
|
* See ["Lifecycle Hooks Guide"](guide/lifecycle-hooks#afterview).
|
2015-09-24 18:40:50 -04:00
|
|
|
*
|
2018-04-05 17:31:44 -04:00
|
|
|
*
|
2015-08-28 21:11:04 -04:00
|
|
|
*/
|
2017-02-23 21:04:51 -05:00
|
|
|
export interface AfterViewInit { ngAfterViewInit(): void; }
|
2015-08-31 21:32:32 -04:00
|
|
|
|
|
|
|
/**
|
2018-04-05 04:58:02 -04:00
|
|
|
* @usageNotes
|
2016-09-14 12:42:41 -04:00
|
|
|
* {@example core/ts/metadata/lifecycle_hooks_spec.ts region='AfterViewChecked'}
|
2015-09-24 18:40:50 -04:00
|
|
|
*
|
2016-09-14 12:42:41 -04:00
|
|
|
* @description
|
2018-04-05 05:16:31 -04:00
|
|
|
* Lifecycle hook that is called after every check of a component's view.
|
|
|
|
*
|
2018-05-18 07:19:29 -04:00
|
|
|
* See ["Lifecycle Hooks Guide"](guide/lifecycle-hooks#afterview).
|
2015-09-24 18:40:50 -04:00
|
|
|
*
|
2018-04-05 17:31:44 -04:00
|
|
|
*
|
2015-08-31 21:32:32 -04:00
|
|
|
*/
|
2017-02-23 21:04:51 -05:00
|
|
|
export interface AfterViewChecked { ngAfterViewChecked(): void; }
|