0
0
Angularframework~10 mins

Observable vs Promise mental model in Angular - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Concept Flow - Observable vs Promise mental model
Start
Create Promise
Promise runs once
Resolve or Reject
Then or Catch
Create Observable
Observable waits
Subscribe called
Emit values multiple times
Complete or Error
End
This flow shows how a Promise runs once and resolves or rejects, while an Observable waits until subscribed and can emit multiple values over time.
Execution Sample
Angular
const promise = new Promise(res => res('Done'));
promise.then(val => console.log(val));

const observable = new Observable(sub => {
  sub.next('First');
  sub.next('Second');
  sub.complete();
});
observable.subscribe(val => console.log(val));
This code creates a Promise that resolves once and an Observable that emits two values before completing.
Execution Table
StepActionPromise StateObservable StateOutput
1Create PromisePendingNot created
2Create ObservablePendingWaiting for subscription
3Promise executor runsPendingWaiting for subscription
4Promise then() calledResolvedWaiting for subscription
5Promise then() callback runsResolvedWaiting for subscriptionConsole logs: Done
6Observable subscribe() calledResolvedSubscribed
7Observable emits 'First'ResolvedEmittingConsole logs: First
8Observable emits 'Second'ResolvedEmittingConsole logs: Second
9Observable completesResolvedCompleted
10No more emissionsResolvedCompleted
💡 Promise resolves once and Observable completes after emitting multiple values.
Variable Tracker
VariableStartAfter Step 3After Step 6After Step 9
promiseStatePendingPendingResolvedResolved
observableStateNot createdWaiting for subscriptionSubscribedCompleted
outputDoneDone, First, Second
Key Moments - 3 Insights
Why does the Promise output only once while the Observable outputs multiple times?
Because the Promise executor runs immediately and resolves once (see execution_table step 4 and 5), while the Observable waits for subscription and can emit many values over time (see steps 6 to 8).
When does the Observable start emitting values?
Only after subscribe() is called (execution_table step 6), unlike the Promise which runs immediately upon creation.
Can a Promise emit multiple values like an Observable?
No, a Promise resolves or rejects once and cannot emit multiple values, as shown by the single output at step 5 in the execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does the Promise resolve?
AStep 3
BStep 6
CStep 8
DStep 9
💡 Hint
Check the Promise State column in execution_table at step 3.
At which step does the Observable start emitting values?
AStep 4
BStep 7
CStep 6
DStep 10
💡 Hint
Look at the Observable State and Output columns in execution_table.
If the Observable did not call complete(), what would happen?
AIt would emit values forever
BIt would never emit any values
CIt would emit values but never signal completion
DIt would behave like a Promise
💡 Hint
Refer to the Observable State column and the meaning of complete() in execution_table steps 8 and 9.
Concept Snapshot
Promise:
- Runs immediately
- Resolves or rejects once
- Emits single value

Observable:
- Waits for subscription
- Can emit multiple values over time
- Can complete or error

Use Observable for streams, Promise for single async result.
Full Transcript
This visual execution compares Promise and Observable in Angular. A Promise starts running immediately when created, resolving or rejecting once. The Observable waits until you subscribe, then can emit many values over time before completing. The execution table shows Promise resolving at step 4 and emitting one output at step 5. The Observable starts emitting after subscription at step 6, outputs multiple values at steps 7 and 8, and completes at step 9. Variables track promiseState and observableState changes. Key moments clarify why Promise emits once and Observable can emit many times. The quiz tests understanding of when each runs and emits. This helps beginners see the difference in timing and behavior between Promise and Observable.