为什么,何时以及如何在Angular中使用此sintaxis?

问题描述 投票:0回答:1

我一直在寻找有关依赖注入的信息,然后找到了这篇文章:

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>

引起了我的注意。

我相信自定义角度标签(自定义标签选择器)之间没有任何关系。

我想了解有关它的更多信息,但我不知道要使用哪些搜索词以及该语法如何工作。

您能帮我解释或分享有关它的信息吗?

javascript angular dependency-injection syntax documentation
1个回答
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>访问该内容。

© www.soinside.com 2019 - 2024. All rights reserved.