Angular: Avoid the Subscribe() Method for Observables

Outdated tech products on a desk.
Outdated tech products on a desk.
Photo by Lorenzo Herrera on Unsplash.

What Is an Observable?

Subscribe Function

serviceFunctionReturningObservable( flag: Flag ):
Observable<boolean> {}

The suboptimal version of my code (without using an async pipe) with regular .subscribe()

[isSomeBooleanVarToPassDownToChildComp]="isSomeBooleanVarToPassDownToChildComp"

AsyncPipe

Why Use AsyncPipe?

Another Example of the Principle

Initial working code with .subscribe()

Final refactored code without using .subscribe()

Exceptions

Written by

DataScience | ML | 2x Kaggle Expert. Ex Fullstack Engineer and Ex International Financial Analyst. https://www.linkedin.com/in/rohan-paul-b27285129/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store