angular-cn/public/docs/js/latest/api/di/HostMetadata-class.jade

57 lines
1.1 KiB
Plaintext
Raw Normal View History

p.location-badge.
exported from <a href='../di'>angular2/di</a>
defined in <a href="https://github.com/angular/angular/tree/2.0.0-alpha.33/modules/angular2/src/di/metadata.ts#L138-L166">angular2/src/di/metadata.ts (line 138)</a>
:markdown
Specifies that an injector should retrieve a dependency from any injector until reaching the
closest host.
## Example
```
class Dependency {
}
class NeedsDependency {
constructor(public @Host() dependency:Dependency) {}
}
var parent = Injector.resolveAndCreate([
bind(Dependency).toClass(HostDependency)
]);
var child = parent.resolveAndCreateChild([]);
var grandChild = child.resolveAndCreateChild([NeedsDependency, Depedency]);
var nd = grandChild.get(NeedsDependency);
expect(nd.dependency).toBeAnInstanceOf(HostDependency);
```
.l-main-section
h2 Annotations
.l-sub-section
h3.annotation CONST
pre.prettyprint
code.
@CONST()
.l-main-section
h2 Members
.l-sub-section
h3 toString
pre.prettyprint
code.
toString()
:markdown