I have two components one parent and a child i want to access a variable in parent component from child using DI but i am not getting that.i have made a plunker demo http://plnkr.co/edit/fcfweLJAmadKVWKXF25l?p=preview ... I tried to access the value of variable from child and got corrrectly but not from parent to child.This is how i am accessing variable in child component
@Component({
selector: 'child',
providers:[AppComponent]
template: '<h1>My second Angular 2 App</h1>'
})
class NameComponent {
name:string;
constructor(AppComponent: AppComponent) {
this.name = AppComponent.getName();
console.log(this.name);
}
}
I want to know is it possible to access variable from parent using DI? some body please tell me how to get the values