What is Observable?
Observable is a data stream that you can observe (that is, subscribe to) and receive values from over time.
A real-life example:
Imagine a button. Every click is a new event.
Observable is like a radio: it transmits signals, and you just listen.
In code:
ts
const stream$ = of(1, 2, 3); // stream of numbers
stream$.subscribe(value => {
console.log(value); // logs: 1, then 2, then 3
});stream$is the Observable.subscribe()starts listening- inside it: what to do with each new value
Where it's used in Angular:
HttpClient.get(...)→ returns an ObservableFormControl.valueChanges→ the input streamrouter.events→ the router event stream
What Observables can do:
- emit many values
- work with asynchrony (requests, timers)
- use operators (
map,filter,switchMap,debounceTime) - complete or throw an error
Conclusion:
Observable is like a pipe that data flows through.
You can stand next to it (subscribe) and react to every "drop".
This is the foundation of reactivity in Angular and RxJS.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.