角2子组件是指父组件 [英] Angular 2 child component refers to parent component

查看:125
本文介绍了角2子组件是指父组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含三个组件的应用程序。应用程序,EditView中,对话框。

I have an application which contains three components. Application, EditView,Dialog.

应用程序组件包含了可以包含很多其他组件EditView中,一个对话框组件(如对话框组件可见的网页)EditView中的组件。

Application components contains EditView components which can contain many other EditView components and one Dialog component( if Dialog component is visible on a page).

对话框组件包含应用程序组件。当我把在对话框分量声明路径:

Dialog component contains Application component. When I put that in Dialog component in declaration path:

directives:[Application]

我'得到这个错误:

I'am getting this error:

在组件对话框的景观未定义意外的指导价值。

Unexpected directive value 'undefined' on the View of component 'Dialog'

是否有可能在所有有这样的结构,其中子组件可以包含对于一些条件上水平分量?

Is it possible at all to have such structure where child component can contain component from upper level regarding some conditions?

如果我从对话框滴应用程序组件或与其它组件替代它,它工作正常。

If I drop Application component from Dialog or replace it with other components it works fine.

Zlaja

推荐答案

将它放到指令列表将无法正常工作,但你仍然可以有它在孩子指令的构造函数注入可以访问父组件:

Putting it in the directives list won't work, but you can still have access to the parent component by having it injected in the constructor of the child directive:

constructor(@Host(Application) application: Application) {

}

和父组件可以使用get子组件的实时列表 @Query

And the parent component can get a live list of child components using @Query:

constructor(@Query(EditView) editViews: QueryList<EditView>){

}

这篇关于角2子组件是指父组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆