question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

question: why some of injected services are undefined?

See original GitHub issue

The problem: I have 3 services:

ApiHelper

@Service()
export class ApiHelper {
	// contains only methods, none of services are injected
}

LoginService

@Service()
export class SecurityService {
    @Inject()
    private loginService: LoginService;
}

And SecurityService

@Service()
export class LoginService {
    constructor(
        private apiHelper: ApiHelper,
        private securityService: SecurityService,
    ) {
        console.log(this.securityService); // undefined
        console.log(Container.get(SecurityService)); // instance of SecurityService
    }
}

And the problem is that securityService is undefined, while Container.get(SecurityService) works good.

What is wrong here?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
vs4vijaycommented, Jan 24, 2022

We’re facing the same issue, same code worked a week ago. Now it gives undefined value from TypeDI.

0reactions
vs4vijaycommented, Feb 16, 2022

@attilaorosz Looks like I had some circular dependency due to usage of index.ts… I imported directly without using index.ts, and it started working.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 7 : Injected service is undefined - Stack Overflow
I can't see the relation between the code in the question, and arrow functions. The OP only talks about constructor s, he nevers...
Read more >
Angular injected service is undefined : r/Angular2 - Reddit
Your custom service has the providedIn: 'root' property, but that only tells Angular that it will be a singleton, so only one instance...
Read more >
How to Implement Services and Dependency Injection in ...
If a service is injected in any other component, the same instance of the service is available for that component and all it's...
Read more >
Angular – Use of access modifier while injection of service
The error is can't access property or function, because particular service is undefined. In my case, I have a function called run() which...
Read more >
Inject Service From Another Module in NestJS (2022)
I often read the question of how to inject a service/provider from another module. In this article, I wanna explain how to deal...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found