167 lines
3.4 KiB
Plaintext
167 lines
3.4 KiB
Plaintext
|
|
p.location-badge.
|
|
exported from <a href='../annotations'>angular2/annotations</a>
|
|
defined in <a href="https://github.com/angular/angular/tree/2.0.0-alpha.33/modules/angular2/src/core/annotations_impl/annotations.ts#L900-L1037">angular2/src/core/annotations_impl/annotations.ts (line 900)</a>
|
|
|
|
: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 <a href='View-var.html'><code>View</code></a> 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() {
|
|
}
|
|
|
|
}
|
|
```
|
|
|
|
|
|
|
|
|