2015-07-27 22:12:30 -07:00
p.location-badge.
2015-09-01 13:55:47 -07:00
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#L728-L848">angular2/src/core/metadata/directives.ts (line 728)</a>
2015-07-27 22:12:30 -07:00
:markdown
2015-09-01 13:55:47 -07:00
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.
2015-07-28 13:28:47 -07:00
.l-main-section
h2 Annotations
.l-sub-section
h3.annotation CONST
pre.prettyprint
code.
@CONST()
2015-07-27 22:12:30 -07:00
.l-main-section
h2 Members
.l-sub-section
h3 constructor
pre.prettyprint
code.
2015-08-02 23:08:36 -07:00
constructor({selector, properties, events, host, exportAs, lifecycle, bindings, viewBindings,
2015-09-01 13:55:47 -07:00
changeDetection = ChangeDetectionStrategy.Default, compileChildren = true}?: {
2015-07-30 11:19:45 -07:00
selector?: string,
2015-09-01 13:55:47 -07:00
properties?: string[],
events?: string[],
2015-07-30 11:19:45 -07:00
host?: StringMap<string, string>,
2015-09-01 13:55:47 -07:00
lifecycle?: LifecycleEvent[],
bindings?: any[],
2015-07-30 11:19:45 -07:00
exportAs?: string,
compileChildren?: boolean,
2015-09-01 13:55:47 -07:00
viewBindings?: any[],
changeDetection?: ChangeDetectionStrategy,
2015-07-30 11:19:45 -07:00
})
2015-07-27 22:12:30 -07:00
:markdown
.l-sub-section
h3 changeDetection
:markdown
Defines the used change detection strategy.
When a component is instantiated, Angular creates a change detector, which is responsible for
2015-09-01 13:55:47 -07:00
propagating the component's bindings.
2015-07-27 22:12:30 -07:00
The `changeDetection` property defines, whether the change detection will be checked every time
2015-09-01 13:55:47 -07:00
or only when the component tells it to do so.
2015-07-27 22:12:30 -07:00
.l-sub-section
2015-08-02 23:08:36 -07:00
h3 viewBindings
2015-07-27 22:12:30 -07:00
:markdown
Defines the set of injectable objects that are visible to its view dom children.
## Simple Example
Here is an example of a class that can be injected:
```
class Greeter {
greet(name:string) {
return 'Hello ' + name + '!';
}
}
@Directive({
selector: 'needs-greeter'
})
class NeedsGreeter {
greeter:Greeter;
constructor(greeter:Greeter) {
this.greeter = greeter;
}
}
@Component({
selector: 'greet',
2015-08-02 23:08:36 -07:00
viewBindings: [
2015-07-27 22:12:30 -07:00
Greeter
]
})
@View({
template: `<needs-greeter></needs-greeter>`,
directives: [NeedsGreeter]
})
class HelloWorld {
}
```