繁体   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