简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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