1 How to use behavior subjects in angular 6?
The BehaviorSubject is used to hold the values that are to be shared with other components. You can subscribe to data with the BehaviorSubject that needs to be shared with other components.
You can subscribe to the data using the Behavior Subject service as the following.
//inject service into a component
dataService.data.subscribe(data => {
//do whatever needs doing when data changes
})
//update the value of data in the service
dataService.updateData(newData);