具有动态非共享组件的 Angular2 共享组件
Angular2 Shared component with dynamic not shared components
我有两个模块(M1、M2),每个模块上都有两个组件(CL1、CI2、CL3、CI4):一个 ListComponent 和一个 ItemComponent。我创建了一个共享模块,它有 SearchComponent 来寻找项目来填充列表。 SearchComponent 调用后端服务,它 returns json 带有 CI2 或 CI4 数据,视情况而定。
问题是我想在 SearchComponent 中重新使用 CI2 和 CI4 来显示搜索结果,但是它们不能在 SharchModule (SM) 上声明,因为它们已经在 M1 和 M2 上。此外,这会在 M1 <-> SM 和 M2 <-> SM 之间产生循环依赖。
有什么办法可以将 CI2 和 CI4 重用到 SM 中吗?我找到的唯一方法是为 SM 复制 CI2 和 CI4,但我想避免这种情况。
具有快速样本的 Plunker:
https://plnkr.co/edit/a3xiBz6uUF7OcAaRLD4c
SearchComponent 的第 30 行是应该重用 CI2、CI4 的地方。
<ng-container *ngComponentOutlet="component"></ng-container>
其中组件是 CI2 或 CI4,视情况而定。此外,CI2 和 CI4 不需要导入到搜索模块中。 (ngComponentOutlet 在 Angular 4)。
我有两个模块(M1、M2),每个模块上都有两个组件(CL1、CI2、CL3、CI4):一个 ListComponent 和一个 ItemComponent。我创建了一个共享模块,它有 SearchComponent 来寻找项目来填充列表。 SearchComponent 调用后端服务,它 returns json 带有 CI2 或 CI4 数据,视情况而定。
问题是我想在 SearchComponent 中重新使用 CI2 和 CI4 来显示搜索结果,但是它们不能在 SharchModule (SM) 上声明,因为它们已经在 M1 和 M2 上。此外,这会在 M1 <-> SM 和 M2 <-> SM 之间产生循环依赖。
有什么办法可以将 CI2 和 CI4 重用到 SM 中吗?我找到的唯一方法是为 SM 复制 CI2 和 CI4,但我想避免这种情况。
具有快速样本的 Plunker: https://plnkr.co/edit/a3xiBz6uUF7OcAaRLD4c
SearchComponent 的第 30 行是应该重用 CI2、CI4 的地方。
<ng-container *ngComponentOutlet="component"></ng-container>
其中组件是 CI2 或 CI4,视情况而定。此外,CI2 和 CI4 不需要导入到搜索模块中。 (ngComponentOutlet 在 Angular 4)。