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