Xab*_*bre 7 angular2-directives angular
在角度1.x中,我们可以通过在指令内要求它来引用父控制器.但是,由于整个命名切换为角度2,我似乎无法找到相应的功能?
到目前为止我尝试过的事情:
我不太了解Angular1因此我无法确定require
它的确切用途或用途.
对于你问题中提到的子弹:
父模板
<child [childInput]="parentValue" (childOutput)="doSomethingInParent()">
Run Code Online (Sandbox Code Playgroud)
此DI行为可以防止您在问题中提到的冲突.
<child1 [child1Input]="child2.child2Prop"
(child1Output)="child2doSomethingInChild2()">
<child2 #child2></child2>
Run Code Online (Sandbox Code Playgroud)
constructor(@Host() private parent:ParentComponent) {}
Run Code Online (Sandbox Code Playgroud)
在递归组件(如树)中,这可能特别方便,因为它知道父级是什么.在这种情况下,可能需要额外的装饰器
constructor(@Optional() @SkipSelf() @Host() private parent:ParentComponent) {}
Run Code Online (Sandbox Code Playgroud)
哪里
@Optional()
用于根组件以避免异常,因为没有要注入的相同类型的父组件@SkipSelf()
当它与实际想要注入的父类型相同时,避免组件本身被注入.DI始终从组件本身开始查找提供程序.另请参阅注入与子组件相同类型的父组件
归档时间: |
|
查看次数: |
2190 次 |
最近记录: |