p.location-badge.
exported from angular2/annotations
defined in angular2/src/core/annotations_impl/annotations.ts (line 900)
:markdown
Lifecycle events are guaranteed to be called in the following order:
- `onChange` (optional if any bindings have changed),
- `onInit` (optional after the first check only),
- `onCheck`,
- `onAllChangesDone`
.l-main-section
h2 Members
.l-sub-section
h3 onDestroy
:markdown
Notify a directive whenever a View
that contains it is destroyed.
```
@Directive({
...,
lifecycle: [LifecycleEvent.onDestroy]
})
class ClassSet {
onDestroy() {
// invoked to notify directive of the containing view destruction.
}
}
```
.l-sub-section
h3 onChange
:markdown
Notify a directive when any of its bindings have changed.
This method 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.
:
```
@Directive({
selector: '[class-set]',
properties: [
'propA',
'propB'
],
lifecycle: [LifecycleEvent.onChange]
})
class ClassSet {
propA;
propB;
onChange(changes:{[idx: string, PropertyUpdate]}) {
// 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
}
}
}
```
.l-sub-section
h3 onCheck
:markdown
Notify a directive when it has been checked.
This method 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 every time even when none of the directive's bindings has changed.
:
```
@Directive({
selector: '[class-set]',
lifecycle: [LifecycleEvent.onCheck]
})
class ClassSet {
onCheck() {
}
}
```
.l-sub-section
h3 onInit
:markdown
Notify a directive when it has been checked the first itme.
This method 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 once.
:
```
@Directive({
selector: '[class-set]',
lifecycle: [LifecycleEvent.onInit]
})
class ClassSet {
onInit() {
}
}
```
.l-sub-section
h3 onAllChangesDone
:markdown
Notify a directive when the bindings of all its children have been checked (whether they have
changed or not).
:
```
@Directive({
selector: '[class-set]',
lifecycle: [LifecycleEvent.onAllChangesDone]
})
class ClassSet {
onAllChangesDone() {
}
}
```