繁体   English   中英

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

[英]Angular - Render components inside custom component

我有以下代码:

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

如何在我的app-device组件内的特定位置显示我的app-custom-slide-toggleapp-custom-checkbox-list组件?

我正在阅读有关加载动态组件的信息,但不知道如何使其在复合组件中工作。

谢谢!

是内容投影。

<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>

现在在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>

其他有详细描述的案例在这里

暂无
暂无

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

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