RXJS Behavior Subject

PHOTO EMBED

Thu Jun 30 2022 17:26:46 GMT+0000 (Coordinated Universal Time)

Saved by @Polly

# Store Pattern
subject = new BehaviorSubject<T>([]) // [] = default value
data$ = Observable<T> = this.subject.asObservable()

data = subject.getValue()
newState = data.slice(0)
subject.next(newState)
content_copyCOPY

Use case navigate from one component/page and back each navigation creates a new instance of the component - ensures that each component has the latest values of the Observable Subject.

https://angular-university.io/lesson/rxjs-behaviorsubject