How to display alert on app level from a child component

前端 未结 1 1530
一个人的身影
一个人的身影 2021-01-17 07:07

I would like to have some rules or suggestions to be able to do this:

I have an alert on app level that I want to show when something is happening on one of my compo

相关标签:
1条回答
  • 2021-01-17 07:30

    I would do it with Observable and Subject. Basically you need a service injected in the shared module of those component so they share state.

    The app (root) component will have a subscription on the public observable of the service. And every component will set the state through that service by calling the .next() on the subject. The observable will return the value of the subject.

    You can check the code here: https://angular.io/guide/component-interaction#parent-and-children-communicate-via-a-service

    The idea is quite similar.

    0 讨论(0)
提交回复
热议问题