簡體   English   中英

如何獲取Angular6組件的內部html並將其添加到組件模板中?

[英]How to get inner html of Angular6 component and add it to component template?

我希望能夠以這種方式將組件和其他 html 傳遞到其他組件中:

<app-container-component>
  <h3>All these items should be displayed in parent component</h3>
  <app-another-component></app-another-component>
</app-container-component>

如何讀取容器組件的內部項目並將它們呈現在組件模板中?

您可以使用“@Input”、“@Output-EventEmitter”的概念。通過使用這些屬性,您可以使用@Input 裝飾器將數據從父組件傳遞到子組件,並使用@output 裝飾器將數據從子組件傳遞到父組件。 在您的情況下, app-container-component 是父組件, app-another-component 是子組件。 您可以訪問以下 URL 以完整了解這些裝飾器:-

https://angular.io/guide/component-interaction

另外,如果您想將組件的 HTML 傳遞給其他組件,則可以使用 ContentChild 或 TemplateReferenceVariable。 有關其他選項,請參閱以下 URL:-

如何將通用 HTML 傳遞給 Angular 2 組件?

我希望這可以幫助你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM