【发布时间】:2017-03-01 20:15:59
【问题描述】:
如何访问孙组件? 例如,我有一个 grandparent.component.ts、parent.component.ts 和 child.component.ts。 child.component.ts 在其模板中有一个按钮列表。 parent.component.ts 包含 child.component.ts。 grandparent.component.ts 包含 parent.component.ts。我想在 grandparent.component.ts 中禁用 child.component.ts 中的按钮。我该怎么做?
【问题讨论】:
-
如果 BeetleJuice 的答案对您来说不可行,并且如果您想直接与
ChildComponent进行交互,而不是先传递给ParentComponent,那么我想不出除了访问之外的其他方法它通过 ElementRef 并手动更改属性。这是一个非常粗略的解决方案。 plnkr.co/edit/CfspDAbXHhSi7COsO9Lt?p=preview -
顺便说一句,你不能先进入
ParentComponent吗?就像来自GrandParentComponent的事件然后ParentComponent接收它然后最终将它传递给ChildComponent?
标签: angular