从不同的组件调用服务以显示消息

Call a service from a different component to display a message

我有一个共享组件警报,它显示使用服务 'alertService'.

的不同警报(错误、成功..)

我有不同的组件使用 'alertService'。

alert 组件在 appComponent 中的调用方式如下: <app-alert></app-alert>

当我从另一个组件调用该服务时,不显示警报,仅当我在调用该服务的组件中调用 <app-alert></app-alert> 时才会显示。

解决方法:我在app.module提供提醒服务 它在 shared.module.

中提供