[英]How to render a component inside another component angular 10
我有,我有渲染的另一個組件內的組件就像一個情況div
另一個里面div
。 假設有兩個組件HStack
& Button
,我希望能夠使用上述兩個組件從任何其他組件執行類似的操作:
<HStack>
<Button>Similar kind of nesting here!</Button>
</HStack>
我怎樣才能做到這一點? 任何幫助將不勝感激!
您正在尋找的是內容投影。
示例代碼:
import { Component } from '@angular/core';
@Component({
selector: 'HStack',
template: `
<ng-content></ng-content>
`
})
export class HStack {}
如何使用:
<HStack>
<Button>Similar kind of nesting here!</Button>
</HStack>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.