0

using this example: enter link description here

everything works perfect - until I make the component a lazyload component, then the loader stops appearing. any idea what I'm missing here?

Cœur
  • 37,241
  • 25
  • 195
  • 267
idekkers
  • 223
  • 1
  • 5
  • 12
  • Do you have any errors in a console? – Lyubimov Roman Aug 13 '17 at 16:23
  • take a look at this page log in to it using fb or google you will see a loading implement that [link](https://rahulrsingh09.github.io/AngularConcepts/comment) – Rahul Singh Aug 13 '17 at 17:26
  • no errors in the console, and when I follow the script with some break points I see it changing in the service to display true, both in normal mode and in lazyload, but for some reason in lazyload even tough it's true the loader does not display – idekkers Aug 14 '17 at 07:23

2 Answers2

1

Services are injectable, Angular creates a singleton for every provider(service) by default. Those singletons are passed to your components. When lazy loading a module, the module providers are re-created. So the components inside that module will get a new instance of the same service. This is why your subscription isn't triggered.

You should create a shared module witch can be used in lazy loaded modules. This answer can help you: https://stackoverflow.com/a/39672933/2640826

Zsolt Tolvaly
  • 3,528
  • 4
  • 26
  • 25
0

OK, found the problem, though I don't understand the reason.

I had a service in a common module, which was (the module) imported to the app module. for some reason these services do not work in a lazyload module, they do work however when I move them from the providers section in the common module to the providers section in the main app module.

will be glad to understand why this happens?

idekkers
  • 223
  • 1
  • 5
  • 12