p.location-badge.
exported from angular2/di
defined in angular2/src/di/metadata.ts (line 123)
:markdown
Specifies that an injector should retrieve a dependency from any ancestor from the same boundary.
## Example
```
class Dependency {
}
class NeedsDependency {
constructor(public @Ancestor() dependency:Dependency) {}
}
var parent = Injector.resolveAndCreate([
bind(Dependency).toClass(AncestorDependency)
]);
var child = parent.resolveAndCreateChild([]);
var grandChild = child.resolveAndCreateChild([NeedsDependency, Depedency]);
var nd = grandChild.get(NeedsDependency);
expect(nd.dependency).toBeAnInstanceOf(AncestorDependency);
```
You can make an injector to retrive a dependency either from itself or its ancestor by setting
self to true.
```
class NeedsDependency {
constructor(public @Ancestor({self:true}) dependency:Dependency) {}
}
```
.l-main-section
h2 Members
.l-sub-section
h3 constructor
pre.prettyprint
code.
constructor({self}?: {self?: boolean})
:markdown
.l-sub-section
h3 toString
pre.prettyprint
code.
toString()
:markdown