简体   繁体   English

Angular - 在自定义组件中渲染组件

[英]Angular - Render components inside custom component

I have the following code:我有以下代码:

<app-device [device]="device">
        <app-custom-slide-toggle></app-custom-slide-toggle>
        <app-custom-checkbox-list></app-custom-checkbox-list>
      </app-device>

How I can show my app-custom-slide-toggle , app-custom-checkbox-list components in a specific location inside my app-device component?如何在我的app-device组件内的特定位置显示我的app-custom-slide-toggleapp-custom-checkbox-list组件?

I was reading about loading dynamic components, but couldn't figure how how to make it work in compuond components.我正在阅读有关加载动态组件的信息,但不知道如何使其在复合组件中工作。

Thanks!谢谢!

It's content projection.是内容投影。

<app-device [device]="device">
  <app-custom-slide-toggle slot-one></app-custom-slide-toggle>
  <app-custom-checkbox-list slot-two></app-custom-checkbox-list>
</app-device>

And now in AppDeviceComponent we should make slots for content:现在在AppDeviceComponent中,我们应该为内容创建插槽:

<!-- device.component.html -->
<div>
    <div class="slot-1">
        <ng-content select="[slot-one]"></ng-content>
    </div>
    <div class="slot-2">
        <ng-content select="[slot-two]"></ng-content>
    </div>
</div>

Another cases with detailed description are here .其他有详细描述的案例在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM