angular - 如何在Angular 8中将动态数据从父级传递给子级ng-content
问题描述
我有一个组件弹出。这是一个简单的组件,您可以将您希望从网页一侧飞出的任何内容/组件包装起来。我们用它来上传文件。该组件使用广播服务来侦听告诉它何时显示和何时隐藏的消息。它使用内容投影(<ng-content></ng-content>)
来允许您将任何内容传递给它。如何将数据从父容器传递 (e.g., <flyout> )
到动态的子组件 - 意思是,弹出的子组件总是不同的。
弹出组件:
<div [ngClass]="{ 'open': show }" class="offcanvas-collapse" [attr.aria-hidden]="show ? 'false': 'true'">
<div class="w-100 d-flex justify-end pv2">
<button class="btn button-secondary-link" type="button" (click)="closeFlyout()">
<span class="nav-text h5 mb0 underline fw7">Close</span>
</button>
</div>
<ng-content></ng-content>
</div>
我阅读了有关 ng-template-outlet 的信息,但为了使弹出组件具有通用性(因此您可以将其包裹在任何组件/内容周围并将该组件/内容转换为弹出窗口),我们使用内容投影。这些 ng-template-outlet 方法看起来像弹出窗口需要了解其潜在子项的一些信息,这使得它不太灵活。
我正在寻找其他可能的方法来实现这一目标。谢谢
解决方案
推荐阅读
- python - 在 Selenium 中使用元标记进行抓取
- html - 图像与主 div 边框重叠
- python - 我的代码会产生 inf 错误,而且它不会。另外,“inf”和“overflow”有什么区别?
- python - 如何在不激活的情况下将 python 包安装到虚拟环境中?
- reactjs - MUI v5 中使用 theme.spacing() 的间距数学
- javascript - 使长方体在旋转的相机角度三个JS中跟随鼠标位置
- python - 如何评估这个嵌套循环?
- nullpointerexception - dspace 7 java.lang.NullPointerException。/core/sites 因内部服务器错误而失败
- c# - 具有多对多控制器的 Asp net core api 发布请求
- c# - 无法将“ColumnExpression”类型的对象转换为“EntityProjectionExpression”类型