I have created a directive that is using component as its template. Both of them use the same service included in providers:
@Component({
selector: 'my-component',
providers: [MyService],
..
}
@Directive({
selector: '[myDirective]',
providers: [MyService]
})
Now here is the problem. They use the same service, but while one is changing the server, the directive that has been register to its change didn't got the change at all:
this.myService.dataUpdated.subscribe
(
(data: someObject) => {
// Do something...
}
)
Seems to me they are not using the same service at all.
I don't see a reason why singleton should not be used for your scenario. It seems to me that singleton should be used on your case, that's why you don't see the changes at all.
Try to provide your service in your NgModule like this
@NgModule({
...
providers: [MyService]
...
Hope this helps.