javascript - 为什么,何时以及如何在 Angular 中使用这个 sintaxis?
问题描述
我正在寻找有关依赖注入的信息,然后我找到了这篇文章:
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>
它引起了我的注意。
我相信自定义角度标签(自定义标签选择器)之间没有任何关系。
我想了解有关它的更多信息,但我不知道要使用哪些搜索词以及该语法是如何工作的。
你能帮我解释或分享有关它的信息吗?
解决方案
这就是所谓的“内容投影”(以前称为“嵌入”)。
查看有关如何在此处使用的教程: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>
。
推荐阅读
- mql4 - 当收盘价交叉并收于某个移动平均线上方至已知摆动低点和摆动高点时,如何计算多少根柱线?
- osgi - OSGI EventAdmin 无法发送事件 - 在 Producer 上获取空点异常
- python - 从 python 生成具有列表中两列的 excel 文件
- jquery - 使用 switchClass 将父类悬停在子类上,但不影响具有同一类的其他 div
- javascript - 通过两个文本查找一个元素
- regex - vscode正则表达式查找/替换字符串中的替换字符
- python - 是否有可编程的方法将文件从 iPad 传输到 PC?(USB 连接)
- go - 使用接口避免 goroutine 在范围内的数据竞争
- django - 如何在 django.auth.contrib 中处理权限/验证
- sql - 这个 PostgreSQL 函数代码在第 17 行的错误是什么?