Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.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中的子组件中插入html?_Angular_Typescript - Fatal编程技术网

如何在angular中的子组件中插入html?

如何在angular中的子组件中插入html?,angular,typescript,Angular,Typescript,我正在尝试将html插入子组件中。基本上是这样的: Parnet内容 我可以找到将数据传递给子组件的引用,但无法找到如何在选择器中传递实际的html?ng内容标记可以在子组件的模板中使用。该标记将接收您在组件选择器之间输入的任何内容。您也可以将与选择属性一起使用 父组件: <child-component> <div sample>Content form parent</div> </child-component> something

我正在尝试将html插入子组件中。基本上是这样的:

Parnet内容


我可以找到将数据传递给子组件的引用,但无法找到如何在选择器中传递实际的html?

ng内容标记可以在子组件的模板中使用。该标记将接收您在组件选择器之间输入的任何内容。

您也可以将
选择属性一起使用

父组件:

<child-component>
    <div sample>Content form parent</div>
</child-component>
something..
<ng-content select="[sample]"></ng-content>
some more...
something..
<div>Content from parent</div>
some more...

内容表单父级
子组件:

<child-component>
    <div sample>Content form parent</div>
</child-component>
something..
<ng-content select="[sample]"></ng-content>
some more...
something..
<div>Content from parent</div>
some more...
什么。。
还有一些。。。
输出:

<child-component>
    <div sample>Content form parent</div>
</child-component>
something..
<ng-content select="[sample]"></ng-content>
some more...
something..
<div>Content from parent</div>
some more...
什么。。
来自家长的内容
还有一些。。。
更多细节