Angular2 - Accessing parent component's variable from child component
<p>I want to access a variable on the parent component from the child component and do something with it. Here is how I am doing it but it looks like its not working as it suppose to:</p>

<p><strong>parent.ts</strong></p>

<pre><code>import {Component,DynamicComponentLoader,ElementRef,AfterViewInit} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';
import {ChildComponent} from './child.ts';


@Component({
    selector: 'app',
    template: `&lt;div #child&gt;&lt;/div&gt;`
})
class AppComponent implements AfterViewInit{

    public parentValue = "some value."

    constructor(private _loader:DynamicComponentLoader,private _elementRef:ElementRef) {}
    ngAfterViewInit(){
        this._loader.loadIntoLocation(ChildComponent,this._elementRef,'child').then(child =&gt; {
            child.instance.log = this.callback;
        });
    }

    callback(){
        console.log(this.parentValue);  //logs undefined rather than "some value"
    }

}

bootstrap(AppComponent);
</code></pre>

<p><strong>child.ts</strong></p>

<pre><code>import {Component} from 'angular2/core';

@Component({
    selector: "child-component",
    template: "&lt;button (click)='logParentValue()' &gt;Log Value&lt;/button&gt;"
})
export class ChildComponent{
    log:any;
    logParentValue(){
        this.log();
    }
};
</code></pre>

<p>When I try to log the value of parent component's variable from the child component it always logs <code>undefined</code>. Any solution to this?</p>