Bittu Kumar
Mar 24, 2023

Understand subject in Angular

subject is a special type of Observable that allows values to be multicasted to many Observers.
subject can act as both observable and observer.

Three simple steps to understand with simple example in Angular,
1. Create subject in service file.
2. Use subscribe method in ngOnInit or Constructor →to the subject created in the component where you want data.
3. Use next method to the same subject to emit data.

Mini project to understand this concept,
username will be updated in each component, when you send username data from any input field of components.

You can get full source code in github repo:-
https://lnkd.in/gHuiDPGk

and live from stackblitz:-
https://lnkd.in/gaGEFtEv

Please go through the code and live example in stackblitz,

Feel free to discuss, Thanks.