2015-07-27 22:12:30 -07:00
p.location-badge.
exported from <a href='../di'>angular2/di</a>
2015-08-02 23:08:36 -07:00
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>
2015-07-27 22:12:30 -07:00
:markdown
2015-08-02 23:08:36 -07:00
Specifies that an injector should retrieve a dependency from any injector until reaching the
closest host.
2015-07-27 22:12:30 -07:00
## Example
```
class Dependency {
}
class NeedsDependency {
2015-08-02 23:08:36 -07:00
constructor(public @Host() dependency:Dependency) {}
2015-07-27 22:12:30 -07:00
}
var parent = Injector.resolveAndCreate([
2015-08-02 23:08:36 -07:00
bind(Dependency).toClass(HostDependency)
2015-07-27 22:12:30 -07:00
]);
var child = parent.resolveAndCreateChild([]);
var grandChild = child.resolveAndCreateChild([NeedsDependency, Depedency]);
var nd = grandChild.get(NeedsDependency);
2015-08-02 23:08:36 -07:00
expect(nd.dependency).toBeAnInstanceOf(HostDependency);
2015-07-27 22:12:30 -07:00
```
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 toString
pre.prettyprint
code.
toString()
:markdown