265 lines
5.1 KiB
Plaintext
265 lines
5.1 KiB
Plaintext
|
|
p.location-badge.
|
|
exported from <a href='../metadata'>angular2/metadata</a>
|
|
defined in <a href="https://github.com/angular/angular/tree/2.0.0-alpha.36/modules/angular2/src/core/metadata/directives.ts#L848-L1048">angular2/src/core/metadata/directives.ts (line 848)</a>
|
|
|
|
:markdown
|
|
Annotations provide the additional information that Angular requires in order to run your
|
|
application. This module
|
|
contains <a href='ComponentMetadata-class.html'><code>ComponentMetadata</code></a>, <a href='DirectiveMetadata-class.html'><code>DirectiveMetadata</code></a>, and <a href='ViewMetadata-class.html'><code>ViewMetadata</code></a>
|
|
annotations, as well as
|
|
the <a href='../di/Host-var.html'><code>Host</code></a> annotation that is used by Angular to resolve dependencies.
|
|
.l-main-section
|
|
h2 Members
|
|
.l-sub-section
|
|
h3 OnInit
|
|
|
|
|
|
:markdown
|
|
Notify a directive when it has been checked the first time.
|
|
|
|
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 OnDestroy
|
|
|
|
|
|
:markdown
|
|
Notify a directive whenever a <a href='ViewMetadata-class.html'><code>ViewMetadata</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 OnChanges
|
|
|
|
|
|
: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.OnChanges]
|
|
})
|
|
class ClassSet {
|
|
propA;
|
|
propB;
|
|
onChanges(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 DoCheck
|
|
|
|
|
|
: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.DoCheck]
|
|
})
|
|
class ClassSet {
|
|
doCheck() {
|
|
}
|
|
}
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.l-sub-section
|
|
h3 AfterContentInit
|
|
|
|
|
|
:markdown
|
|
Notify a directive when the bindings of all its content children have been checked the first
|
|
time (whether they
|
|
have changed or not).
|
|
|
|
|
|
|
|
```
|
|
@Directive({
|
|
selector: '[class-set]',
|
|
lifecycle: [LifecycleEvent.AfterContentInit]
|
|
})
|
|
class ClassSet {
|
|
|
|
afterContentInit() {
|
|
}
|
|
|
|
}
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.l-sub-section
|
|
h3 AfterContentChecked
|
|
|
|
|
|
:markdown
|
|
Notify a directive when the bindings of all its content children have been checked (whether
|
|
they
|
|
have changed or not).
|
|
|
|
|
|
|
|
```
|
|
@Directive({
|
|
selector: '[class-set]',
|
|
lifecycle: [LifecycleEvent.AfterContentChecked]
|
|
})
|
|
class ClassSet {
|
|
|
|
afterContentChecked() {
|
|
}
|
|
|
|
}
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.l-sub-section
|
|
h3 AfterViewInit
|
|
|
|
|
|
:markdown
|
|
Notify a directive when the bindings of all its view children have been checked the first time
|
|
(whether they
|
|
have changed or not).
|
|
|
|
|
|
|
|
```
|
|
@Directive({
|
|
selector: '[class-set]',
|
|
lifecycle: [LifecycleEvent.AfterViewInit]
|
|
})
|
|
class ClassSet {
|
|
|
|
afterViewInit() {
|
|
}
|
|
|
|
}
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.l-sub-section
|
|
h3 AfterViewChecked
|
|
|
|
|
|
:markdown
|
|
Notify a directive when the bindings of all its view children have been checked (whether they
|
|
have changed or not).
|
|
|
|
|
|
|
|
```
|
|
@Directive({
|
|
selector: '[class-set]',
|
|
lifecycle: [LifecycleEvent.AfterViewChecked]
|
|
})
|
|
class ClassSet {
|
|
|
|
afterViewChecked() {
|
|
}
|
|
|
|
}
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|