为什么、何时以及如何在 Angular 中使用这个 sintaxis?
Why, when and how use this sintaxis in Angular?
我在寻找有关依赖注入的信息,然后我找到了这篇文章:
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>
它引起了我的注意。
我相信自定义 angular 标签(自定义标签选择器)之间没有任何关系。
我想了解有关它的更多信息,但我不知道要使用哪些搜索词以及该语法的工作原理。
你能帮我解释一下或分享相关信息吗?
即所谓"Content Projection"(以前称为"transclusion")。
在此处查看有关如何使用它的教程: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>
访问该内容。
我在寻找有关依赖注入的信息,然后我找到了这篇文章:
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>
它引起了我的注意。
我相信自定义 angular 标签(自定义标签选择器)之间没有任何关系。
我想了解有关它的更多信息,但我不知道要使用哪些搜索词以及该语法的工作原理。
你能帮我解释一下或分享相关信息吗?
即所谓"Content Projection"(以前称为"transclusion")。
在此处查看有关如何使用它的教程: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>
访问该内容。