Send Data from one component to multiple components in real time with Subject & Observer in Angular

Опубликовано: 29 Июнь 2024
на канале: XAdmin
87
3

In this video, we are going to discuss the approach to tranfer the data from one component to multiple components in real time with Subject and Observer in Angular application

Sharing Data via Service & Subject

This approach is commonly used for communication between components when they are not directly related by parent-child relationships
This approach is known as Subject-Observer pattern or also called as Publish-subscribe pattern
Service component : Acts as a centralized place to manage data communication between components using Subject for sending data and Observable for receiving data .

Important Notes:-

Observable Nature: Subject is both an Observable and an Observer. It can emit values (next(data)) and be subscribed to (getData() returns an Observable).

Subscription: Components or services that want to receive the emitted data should subscribe to getData(). It's important to unsubscribe from this Observable to prevent memory leaks, typically done in the ngOnDestroy lifecycle hook.

Multicasting: Subject allows multicasting, meaning it broadcasts the same data to multiple subscribers. This makes it useful for scenarios where multiple parts of your application need to react to the same events or data changes.
#angulardevelopment #angular17 ‪@xadmin‬


Смотрите видео Send Data from one component to multiple components in real time with Subject & Observer in Angular онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь XAdmin 29 Июнь 2024, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 87 раз и оно понравилось 3 людям.