I have built a shared data service that\'s designed to hold the users login details which can then be used to display the username on the header, but I cant get it to work.
Add it in @NgModule.providers array of your AppModule
:
if you add it in @Component.providers array then you are limiting the scope of SharedDataService
instance to that component and its children.
in other words each component has its own injector which means that headerComponent
will make its own instance of SharedDataService
and loginComponent
will make its own instance.