-
Notifications
You must be signed in to change notification settings - Fork 24.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple instances of services create #6344
Comments
Could you set up a plnkr, please? |
https://embed.plnkr.co/xnVaqaUjZptFntu0yZMD/ Creates three components (Header,Content,Footer) that all use TestService. Each component gets a different instance of TestService (which is actually slightly different than what I'm seeing locally but still demonstrates the general issue). |
After re-reading the doc's it's working as it's supposed to with Providers creating a new instance for each component. Apologies for the misunderstanding. |
If you want a single instance, only add it once to providers in |
Yeah, if you really want an application-wise singleton, you could do:
And then do not use providers:
|
Lol, beat me for 2 seconds 😆 |
Appreciate the follow up. |
@ericcarraway less characters in my post ;-) |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm running into an issue with Beta.0 where services are being instantiated twice (easily verified by putting a console.log() into the services constructor). In some cases, components are being issued different instances of the same service and creates the following problem.
What's interesting is I have another service that follows the same pattern and while two instances are created, the same instance is always injected so everything works properly.
It does not seem to be dependent on the number of times a Service is listed as provider, it's always initialized twice.
The text was updated successfully, but these errors were encountered: