80 lines
1.5 KiB
Plaintext
80 lines
1.5 KiB
Plaintext
|
|
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.32/modules/angular2/src/di/metadata.ts#L123-L160">angular2/src/di/metadata.ts (line 123)</a>
|
|
|
|
: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 Annotations
|
|
.l-sub-section
|
|
h3.annotation CONST
|
|
pre.prettyprint
|
|
code.
|
|
@CONST()
|
|
|
|
|
|
.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
|
|
|
|
|
|
|
|
|
|
|
|
|