我试图了解@Host
装饰器如何与view-components 分离。所以我创建了以下注入器树:
class Dependency {
}
@Injectable()
class NeedsDependency {
constructor(@Host() public dependency: Dependency) {
console.log(this.dependency); // outputs 'A', but I expected the error
}
}
const parent = ReflectiveInjector.resolveAndCreate([{provide: Dependency, useValue: 'A'}]);
const child = parent.resolveAndCreateChild([]);
const grandchild = child.resolveAndCreateChild([NeedsDependency]);
grandchild.get(NeedsDependency);
我预计会出现错误,因为据我了解grandchild
注入器的主机是child
,并且注入器中没有Dependency
提供child
。但是,当我运行此代码时,我会'A'
从根注入器中注入。为什么?