angular-cn/public/docs/js/latest/api/lifecycle_hooks/OnChanges-interface.jade

57 lines
1.4 KiB
Plaintext

p.location-badge.
exported from <a href='../lifecycle_hooks'>angular2/lifecycle_hooks</a>
defined in <a href="https://github.com/angular/angular/tree/2.0.0-alpha.37/modules/angular2/src/core/compiler/interfaces.ts#L12-L52">angular2/src/core/compiler/interfaces.ts (line 12)</a>
:markdown
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)
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
}
}
}
```
.l-main-section
h2 Members
.l-sub-section
h3#onChanges onChanges
pre.prettyprint
code.
onChanges(changes: StringMap&lt;string, any&gt;)
:markdown