2015-08-20 17:28:25 -04:00
|
|
|
import {StringMap} from 'angular2/src/core/facade/collection';
|
2015-05-22 16:14:59 -04:00
|
|
|
|
|
|
|
/**
|
2015-08-31 21:32:32 -04:00
|
|
|
* Lifecycle hooks are guaranteed to be called in the following order:
|
|
|
|
* - `OnChanges` (if any bindings have changed),
|
|
|
|
* - `OnInit` (after the first check only),
|
|
|
|
* - `DoCheck`,
|
|
|
|
* - `AfterContentInit`,
|
|
|
|
* - `AfterContentChecked`,
|
|
|
|
* - `OnDestroy` (at the very end before destruction)
|
2015-05-22 16:14:59 -04:00
|
|
|
*/
|
2015-05-27 11:07:37 -04:00
|
|
|
|
|
|
|
/**
|
2015-08-31 21:32:32 -04:00
|
|
|
* Notify a directive when any of its bindings have changed.
|
|
|
|
*
|
|
|
|
* `onChanges` is called right after the directive's bindings have been checked,
|
|
|
|
* and before any of its children's bindings have been checked.
|
|
|
|
*
|
|
|
|
* It is invoked only if at least one of the directive's bindings has changed.
|
|
|
|
*
|
|
|
|
* ## Example:
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* @Component(...)
|
|
|
|
* class MyComponent implements OnChanges {
|
|
|
|
* propA;
|
|
|
|
* propB;
|
|
|
|
*
|
|
|
|
* onChanges(changes: {[idx: string, PropertyUpdate]}): void {
|
|
|
|
* // This will get called after any of the properties have been updated.
|
|
|
|
* if (changes['propA']) {
|
|
|
|
* // if propA was updated
|
|
|
|
* }
|
|
|
|
* if (changes['propA']) {
|
|
|
|
* // if propB was updated
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ```
|
2015-05-27 11:07:37 -04:00
|
|
|
*/
|
2015-09-02 19:43:39 -04:00
|
|
|
export class OnChanges {
|
2015-08-31 21:32:32 -04:00
|
|
|
onChanges(changes: StringMap<string, any>): void {}
|
|
|
|
}
|
2015-05-27 11:07:37 -04:00
|
|
|
|
2015-05-27 13:14:37 -04:00
|
|
|
/**
|
2015-08-31 21:32:32 -04:00
|
|
|
* Notify a directive when it has been checked the first time.
|
|
|
|
*
|
|
|
|
* `onInit` is called right after the directive's bindings have been checked for the first time,
|
|
|
|
* and before any of its children's bindings have been checked.
|
|
|
|
*
|
|
|
|
* It is invoked only once.
|
|
|
|
*
|
|
|
|
* ## Example
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* @Component(...)
|
|
|
|
* class MyComponent @implements OnInit {
|
|
|
|
* onInit(): void {
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ```
|
2015-05-27 13:14:37 -04:00
|
|
|
*/
|
2015-09-02 19:43:39 -04:00
|
|
|
export class OnInit {
|
2015-08-31 21:32:32 -04:00
|
|
|
onInit(): void {}
|
|
|
|
}
|
2015-05-27 13:14:37 -04:00
|
|
|
|
|
|
|
/**
|
2015-08-31 21:32:32 -04:00
|
|
|
* Overrides the default change detection.
|
|
|
|
*
|
|
|
|
* `doCheck()` gets called to check the changes in the directives instead of the default
|
|
|
|
* change detection mechanism.
|
|
|
|
*
|
|
|
|
* It is invoked every time the change detection is triggered.
|
|
|
|
*
|
|
|
|
* ## Example
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* @Component(...)
|
|
|
|
* class MyComponent implements DoCheck {
|
|
|
|
* doCheck(): void {
|
|
|
|
* // Custom logic to detect changes
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ```
|
2015-05-27 13:14:37 -04:00
|
|
|
*/
|
2015-09-02 19:43:39 -04:00
|
|
|
export class DoCheck {
|
2015-08-31 21:32:32 -04:00
|
|
|
doCheck(): void {}
|
|
|
|
}
|
2015-05-27 13:14:37 -04:00
|
|
|
|
2015-08-28 21:11:04 -04:00
|
|
|
/**
|
2015-08-31 21:32:32 -04:00
|
|
|
* Notify a directive whenever a {@link ViewMetadata} that contains it is destroyed.
|
|
|
|
*
|
|
|
|
* ## Example
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* @Component(...)
|
|
|
|
* class MyComponent implements OnDestroy {
|
|
|
|
* onDestroy(): void {
|
|
|
|
* // invoked to notify directive of the containing view destruction.
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ```
|
2015-08-28 21:11:04 -04:00
|
|
|
*/
|
2015-09-02 19:43:39 -04:00
|
|
|
export class OnDestroy {
|
2015-08-31 21:32:32 -04:00
|
|
|
onDestroy(): void {}
|
|
|
|
}
|
2015-08-28 21:11:04 -04:00
|
|
|
|
2015-05-27 11:07:37 -04:00
|
|
|
/**
|
2015-08-31 21:32:32 -04:00
|
|
|
* Notify a directive when the bindings of all its content children have been checked the first
|
|
|
|
* time (whether they have changed or not).
|
|
|
|
*
|
|
|
|
* ## Example
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* @Component(...)
|
|
|
|
* class MyComponent implements AfterContentInit {
|
|
|
|
* afterContentInit(): void {
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ```
|
2015-05-27 11:07:37 -04:00
|
|
|
*/
|
2015-09-02 19:43:39 -04:00
|
|
|
export class AfterContentInit {
|
2015-08-31 21:32:32 -04:00
|
|
|
afterContentInit(): void {}
|
|
|
|
}
|
2015-08-28 21:11:04 -04:00
|
|
|
|
|
|
|
/**
|
2015-08-31 21:32:32 -04:00
|
|
|
* Notify a directive when the bindings of all its content children have been checked (whether
|
|
|
|
* they have changed or not).
|
|
|
|
*
|
|
|
|
* ## Example
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* @Component(...)
|
|
|
|
* class MyComponent implements AfterContentChecked {
|
|
|
|
* afterContentChecked(): void {
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ```
|
2015-08-28 21:11:04 -04:00
|
|
|
*/
|
2015-09-02 19:43:39 -04:00
|
|
|
export class AfterContentChecked {
|
2015-08-31 21:32:32 -04:00
|
|
|
afterContentChecked(): void {}
|
|
|
|
}
|
2015-08-28 21:11:04 -04:00
|
|
|
|
|
|
|
/**
|
2015-08-31 21:32:32 -04:00
|
|
|
* Notify a directive when the bindings of all its view children have been checked the first time
|
|
|
|
* (whether they have changed or not).
|
|
|
|
*
|
|
|
|
* ## Example
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* @Component(...)
|
|
|
|
* class MyComponent implements AfterViewInit {
|
|
|
|
* afterViewInit(): void {
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ```
|
2015-08-28 21:11:04 -04:00
|
|
|
*/
|
2015-09-02 19:43:39 -04:00
|
|
|
export class AfterViewInit {
|
2015-08-31 21:32:32 -04:00
|
|
|
afterViewInit(): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify a directive when the bindings of all its view children have been checked (whether they
|
|
|
|
* have changed or not).
|
|
|
|
*
|
|
|
|
* ## Example
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* @Component(...)
|
|
|
|
* class MyComponent implements AfterViewChecked {
|
|
|
|
* afterViewChecked(): void {
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
*/
|
2015-09-02 19:43:39 -04:00
|
|
|
export class AfterViewChecked {
|
2015-08-31 21:32:32 -04:00
|
|
|
afterViewChecked(): void {}
|
|
|
|
}
|