我一直在寻找有关依赖注入的信息,然后找到了这篇文章:
https://medium.com/angular-chile/inyecci%C3%B3n-de-componentes-y-directivas-en-angular-6ae75f64be66
在那里我看到了这种语法
<ui-card>
<h1>Your daily @agadmator quote</h1>
<p>Congratulations! You are an excellent analyzer of hypothetical end game positions and that never actually happened.</p>
</ui-card>
它引起了我的注意。
我相信自定义角度标签(自定义标签选择器)之间没有任何关系。
我想了解有关它的更多信息,但我不知道要使用哪些搜索词以及该语法如何工作。
您能帮我解释或分享有关它的信息吗?
答案 0 :(得分:1)
这称为“内容投影”(以前称为“包含”)。
在此处查看有关其用法的教程:https://scotch.io/tutorials/angular-2-transclusion-using-ng-content
简而言之,通常将数据传递给组件:
<my-card [content]="myVar"></my-card>
但是,当您需要传递其他HTML元素时,可以使用内容投影:
<my-card>
<h1>Hello world</h1>
</my-card>
在MyCardComponent
内,您可以使用特殊标签<ng-content>
访问该内容。