簡體   English   中英

Angular-如何在手動嵌套的組件中重用數據

[英]Angular - How to reuse data in manually nested components

我有兩個Angular組件, checklist-pagechecklist checklist-page從后端下載數據

我想用checklist組件多次內部checklist-page組件。

我想在checklist組件中使用checklist-page的下載數據。

不同之處在於,我無法選擇基本的父子組件嵌套方式,因為我想以這種方式自定義地設置每個checklist實例的參數:

<checklist-page [type]='locations'>
   <checklist [checklistData]="parentComponentData" [filter]='visited'>
   <checklist [checklistData]="parentComponentData" [filter]='remaining'>
   <checklist [checklistData]="parentComponentData" [filter]='visited' [userId]=123>
   <checklist [checklistData]="parentComponentData" [filter]='visited' [userId]=234>
   <checklist [checklistData]="parentComponentData" [filter]='remaining' [userId]=456>
   <checklist [checklistData]="parentComponentData" [filter]='remaining' [userId]=456>
   .
   .
   .
</checklist-page>

簡而言之,我不知道checklist-page模板的內容是什么,它可能有所不同。

在這種情況下,如何將數據從checklist-page傳遞到checklist

您可以從此鏈接使用一種方法。我更喜歡一種服務https://angularfirebase.com/lessons/sharing-data-between-angular-components-four-methods/

您可以使用動態組件加載器https://angular.io/guide/dynamic-component-loader

暫無
暫無

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

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