Observables Explained for Angular Beginners
Understand Observables with simple examples so RxJS feels practical, not confusing.
Angular uses Observables everywhere (HTTP, Router, Forms). Think of an Observable like a stream of values over time. ## Simple mental model - A Promise gives you one value later. - An Observable can give you many values over time. ## Observable stream picture ```mermaid flowchart LR A[Observable] --> B[Value 1] A --> C[Value 2] A --> D[Value 3] ``` ## Example: interval stream ```ts import { interval } from 'rxjs'; interval(1000).subscribe(n => { console.log('Tick:', n); }); ``` This logs a number every second. ## Why Angular likes Observables - cancelable (unsubscribe) - supports streaming updates - powerful operators (map, filter, switchMap) ## Important: unsubscribe (basic rule) If you subscribe to long-lived streams, clean up in `ngOnDestroy`. HTTP calls complete automatically, so they usually do not need manual unsubscribe. > Next: Use async pipe to avoid manual subscribe and unsubscribe.