简体   繁体   English

Angular-如何在手动嵌套的组件中重用数据

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

I have two Angular components, checklist-page and checklist . 我有两个Angular组件, checklist-pagechecklist checklist-page downloads the data from the backend checklist-page从后端下载数据

I would like to use the checklist component multiple times inside the checklist-page component. 我想用checklist组件多次内部checklist-page组件。

I'd like to use the downloaded data of checklist-page in checklist components. 我想在checklist组件中使用checklist-page的下载数据。

The twist is, I can't choose the basic parent-child component nesting way, because I would like to customly parameterize each checklist instances this way: 不同之处在于,我无法选择基本的父子组件嵌套方式,因为我想以这种方式自定义地设置每个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>

So, in short, I don't know exactly what is the content of the checklist-page template, it can be vary. 简而言之,我不知道checklist-page模板的内容是什么,它可能有所不同。

How can I pass the data from checklist-page to checklist in this scenario? 在这种情况下,如何将数据从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