
p.location-badge.
  exported from <a href='../core'>angular2/core</a>
  defined in <a href="https://github.com/angular/angular/tree/3a0410a/modules/angular2/src/core/annotations_impl/visibility.ts#L110-L173">angular2/src/core/annotations_impl/visibility.ts (line 110)</a>

:markdown
  Specifies that an injector should retrieve a dependency from any ancestor element within the same
  shadow boundary.
  
  An ancestor is any element between the parent element and the shadow root.
  
  Use <a href='../annotations/Unbounded-var.html'><code>Unbounded</code></a> if you need to cross upper shadow boundaries.
  
  ## Example
  
  Here is a simple directive that retrieves a dependency from an ancestor element.
  
  ```
  @Directive({
    selector: '[dependency]',
    properties: [
      'id: dependency'
    ]
  })
  class Dependency {
    id:string;
  }
  
  
  @Directive({
    selector: '[my-directive]'
  })
  class Dependency {
    constructor(@Ancestor() dependency:Dependency) {
      expect(dependency.id).toEqual(2);
    };
  }
  ```
  
   We use this with the following HTML template:
  
  ```
  <div dependency="1">
    <div dependency="2">
      <div>
        <div dependency="3" my-directive></div>
      </div>
    </div>
  </div>
  ```
  
  The `@Ancestor()` annotation in our constructor forces the injector to retrieve the dependency
  from the
  nearest ancestor element:
  - The current element `dependency="3"` is skipped because it is not an ancestor.
  - Next parent has no directives `<div>`
  - Next parent has the `Dependency` directive and so the dependency is satisfied.
  
  Angular injects `dependency=2`.
  
.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

      
      




