I'm unable to instantiate my application when I have the component which is nested under the root component providing
a component which it uses in it's constructor.
import {Component, Injectable} from 'angular2/core';
@Component()
export class GrandChild(){
constructor () {
this.hello = "hey!"
}
}
@Component({
providers: [GrandChild]
})
@Injectable()
export class Child {
constructor(public grandchild: GrandChild) {
this.grandchild = grandchild;
}
}
@Component({
providers: [Child],
template: `Everything rendered fine!`,
selector: 'app'
})
export class App {
kid: Child;
constructor(public child: Child) {
this.kid = child;
}
}
EXCEPTION: No provider for GrandChild! (App -> Child -> GrandChild)
I'm wondering why this behavior is illegal. Let's say I wanted to use the GrandChild
class in my Child
class and simply reference the Child
class in my App
class. This seems to be impossible.
What is the correct way to create the provide
hierarchy?
Thanks a bunch.