DEV Community

Discussion on: Fullscreen toggle functionality in Angular using Directives.

Collapse
 
adisreyaj profile image
Adithya Sreyaj • Edited
private isMaximizedSubject = new BehaviorSubject(false);
isMaximized$ = this.isMaximizedSubject.pipe();
// Another way
isMaximized$ = this.isMaximizedSubject.asObservable();
Enter fullscreen mode Exit fullscreen mode

Both ways convert the subject into an observable. So you convert subjects to observables and expose only the observables to make sure consumers cannot call next() and emit values.

Update: I have changed it to asObservable as I don't want to create this impression. Using asObservable is probably the better approach.

Collapse
 
umairhm profile image
Umair Hafeez

Yeah, I've seen the usage of "asObservable()" more often.

Thread Thread
 
adisreyaj profile image
Adithya Sreyaj

And I guess that's the best approach. So I've updated the code to reflect the same.

Thanks.