Hi All,
Any one can explain why my service instance is created only once , i have implemented eagar and lazy loading with netesd routing , i have injected the service all the components but still its taking the same instance . i have given my stackblitz link below kindly anyone have a look .
i want to check why lazy-loaded module taking same service instance.
https://stackblitz.com/edit/angular-drtk4e


Muthu KumarRank #935 · 2.2K reputationPosted Jan 2, 2019, 10:48 PM EST
If you imported your service file in app module file providers block. Then it will create only one instance.
If you imported your service file in every component like following,
For reference i have changed your stackblitz and mentioned screenshot,
But best practices is using app module for import services.
Karthikeyan KRank #554 · 4.4K reputationPosted Jan 2, 2019, 11:03 PM EST
Muthu KumarRank #935 · 2.2K reputationPosted Jan 2, 2019, 11:13 PM EST
I can't open that link need to login. Can you explain which you want to know?.
Muthu KumarRank #935 · 2.2K reputationPosted Jan 2, 2019, 11:14 PM EST
https://stackoverflow.com/questions/39672816/can-lazy-loaded-modules-share-the-same-instance-of-a-service-provided-by-their-p
Karthikeyan KRank #554 · 4.4K reputationPosted Jan 2, 2019, 11:28 PM EST
Karthikeyan KRank #554 · 4.4K reputationPosted Jan 3, 2019, 12:32 AM EST