最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

typescript - How to resolve circular dependency in angular - Stack Overflow

programmeradmin5浏览0评论

I have components as follows

S1 (stand-alone)

N1 (Non standalone) Base component auth-Module

Now I am using S1 in Base component and N1 in S1 and getting the circular dependency. Can you please help resolve it.

I have components as follows

S1 (stand-alone)

N1 (Non standalone) Base component auth-Module

Now I am using S1 in Base component and N1 in S1 and getting the circular dependency. Can you please help resolve it.

Share Improve this question asked Mar 25 at 4:52 praneethpraneeth 91 bronze badge
Add a comment  | 

3 Answers 3

Reset to default 1

Use Dependency Injection to Break the Cycle

Instead of directly importing N1 in S1, refactor N1 into a service and inject it into S1 instead of using it as a component.

First of all i think you have to make your ni component standalone as well.

Things you may understand

1: use the di instead of direct import

2: make an common service for repeating thing like we create for mui components

3: use lazy loading with nested routing in you project

In the BaseComponent add the import with forwardRef, this will help you avoid circular dependencies error.

@Component({
  ...
  imports: [
    ...
    forwardRef(() => S1Component),
    ...
  ],
  ...
})
BaseComponent {
  ...
发布评论

评论列表(0)

  1. 暂无评论