I have been working on web application in Angular 2+. and i have following situation
component A
|
component B
|
component C
|
component D //click on button -> call apis and return value to component A's variable
In component D
there is button if user click on that we need to call rest API and that API's result should be show in component A
.
Business case : Consider that component A
is your top header which contain point count and form component D
user do some task and based on that task i need to increment that points.
I can achieve this functionality with broadcast service in angular Subject<BroadcastEvent>
(after api return value create broadcast and in component A i am listing that event ) but i am not sure that if there is a better way to do this stuff.
Or i can't use same service in both component because I need to assign value in variable as well as in show in DOM. If i need only DOM element to be updated than service can resolve my problem but i also need in components variable.