Search code examples
angulartypescriptobservableangular2-services

Call a service from a different component to display a message


I have a shared component alert which displays different alerts (error, success..) that uses a service 'alertService'.

I have different components that uses the 'alertService'.

The alert component is called in the appComponent like so: <app-alert></app-alert>

When I call the service from another component the alert isn't displayed, it displays only when I call <app-alert></app-alert> in the component that call the service.


Solution

  • solution: I provide the alert service in the app.module It was provided in the shared.module.