title: How to access view reference of parent component from child component in angular2
body: <p>I have directory structure as follows:</p>
  
  <p><a href="https://i.stack.imgur.com/TBmg4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TBmg4.png" alt="directory structure"></a></p>
  
  <p>I assigned some method of parent component(app.component) to instance variable of it as follows:</p>
  
  <pre><code>export class AppComponent implements AfterViewInit, AfterContentInit{
    @ViewChild('contentLoginModl') contentLoginModlCon: ElementRef;
    @ViewChild('modlSignToApplyTg') modlSignToApplyTg: ElementRef;
    @ViewChild('uploadCV') uploadCV: ElementRef;
    .....
    constructor(){ .... }
    .....
    ngAfterViewInit() {
      this.appState.set('opnLgnAppTmp',this.contentLoginModlCon);
      this.appState.set('opnUpldCvAppTmp',this.uploadCV);
      this.appState.set('opnLgnBfrAppTmp',this.modlSignToApplyTg);
    }
  </code></pre>
  
  <p>appState (service) is shared through all components but when i'm calling a function inside child compinent which access the refrence of parrent view it comes undefined as follows:</p>
  
  <pre><code>TypeError: Cannot read property 'open' of undefined
      at AppState._state.open (http://localhost:5003/static/main.prod.bundle.js:6:3788)
      at AppComponent.opnWithTry (http://localhost:5003/static/main.prod.bundle.js:2:17395)
      at AppComponent.opnLgnBfrApp (http://localhost:5003/static/main.prod.bundle.js:2:2714)
      at EditProfile.starItm (http://localhost:5003/static/main.prod.bundle.js:7:14899)
      at View_EditProfile26.handleEvent_24 (/AppModule/EditProfile/component.ngfactory.js:2700:51)
      at HTMLAnchorElement.&lt;anonymous&gt; (http://localhost:5003/static/vendor.prod.bundle.js:27:22958)
      at ZoneDelegate.invokeTask (http://localhost:5003/static/polyfills.prod.bundle.js:4:12265)
      at Object.onInvokeTask (http://localhost:5003/static/vendor.prod.bundle.js:26:14260)
      at ZoneDelegate.invokeTask (http://localhost:5003/static/polyfills.prod.bundle.js:4:12170)
      at Zone.runTask (http://localhost:5003/static/polyfills.prod.bundle.js:4:8197)
  </code></pre>