Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 具有来宾组件的父子组件树_Angular - Fatal编程技术网

Angular 具有来宾组件的父子组件树

Angular 具有来宾组件的父子组件树,angular,Angular,在Angular 2中,我有一个组件的层次结构。然而,在树中,我需要显示另一个与对象层次结构分离的元素。它将是一个微调器组件。不知怎的,它不想出现 <parent> <child> <grandchild> <spinner></spinner> </grandchild> <child> </parent> parent

在Angular 2中,我有一个组件的层次结构。然而,在树中,我需要显示另一个与对象层次结构分离的元素。它将是一个微调器组件。不知怎的,它不想出现

<parent>
    <child>
        <grandchild>
            <spinner></spinner>
        </grandchild>
    <child>
</parent>

  • parent
    在模板中包括
    child
  • 子项
    在模板中包括
    孙子项
  • grant
    在模板中不包含
    spinner
    ,但希望显示它(它使用
    ng内容
    )。或者,在某个时刻,
    子对象
    可能希望显示微调器
我如何让它工作?父母是否总是必须指定可能的子女?请让我知道我做错了什么

如果将
添加到组件的模板中,则将显示子元素,而不是

这样可以将子组件传递给父组件

@Component({
  selector: 'child'
  template: `<grand-child><ng-content></ng-content></grand-child>`
})
@组件({
选择器:“孩子”
模板:``
})
@组件({
选择器:“孙子”
template:`前一部分内容后一部分内容`
})
然后你可以像这样使用它

<child><my-spinner></my-spinnger></child>


谢谢,但这正是我所认为的工作方式-在plunker中,您将在孙子模板中看到
ng内容。(我对我的帖子进行了更精确的编辑。)或者我忽略了其中的细微差别吗?对不起,我没有看到Plunker。您的Plunker不包含任何
。也许没有按下保存键?对不起,是我的错,事实上,plunker没有被保存,也没有包含granchild。现在它应该是最新的,整个链需要
(如果没有传递子元素,微调器不会这样做)是的,确实如此,但是没有and元素。太好了,谢谢。
<child><my-spinner></my-spinnger></child>