简体   繁体   English

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

[英]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'.我有一个共享组件警报,它显示使用服务“alertService”的不同警报(错误、成功......)。

I have different components that uses the 'alertService'.我有使用“alertService”的不同组件。

The alert component is called in the appComponent like so: <app-alert></app-alert>警报组件在 appComponent 中被调用,如下所示: <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.当我从另一个组件调用该服务时,警报不会显示,只有当我在调用该服务的组件中调用<app-alert></app-alert>时才会显示。

解决方案:我在app.module中提供alert服务,shared.module中提供。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM