Observed against asObservable ()?

I'm new to Angular2, and I'm just curious to know that if I subscribe to _showNavBaror to showNavBarEmitter, both work the same way (see below the code I'm using). is there any difference

public _showNavBar: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(null);
public showNavBarEmitter: Observable<boolean> = this._showNavBar.asObservable();
+4
source share
1 answer

asObservablemakes the original object inaccessible to subscribers. This way you can limit who can subscribe and who can also emit values.

For this you will need to do _showNavBar private, though.

+6
source

Source: https://habr.com/ru/post/1669922/


All Articles