All quizzesEasy
Observables & HTTP — Series 2
Preview — 3 of 10 questions
The network tab shows nothing. Why?
javascript
ngOnInit() {
this.http.get<Hero[]>('/api/heroes');
}AThe URL needs a leading http://
BHttpClient observables are cold: the request is only made when something subscribes, and nothing here does
Cget() returns a promise that must be awaited
DThe call needs to run inside NgZone.run
What is the third callback for?
javascript
source$.subscribe({
next: (v) => console.log(v),
error: (e) => console.error(e),
complete: () => console.log('done'),
});Acomplete runs after every next
Bcomplete runs whether the stream ended successfully or with an error
Ccomplete runs once when the stream ends normally — and never if it errored, since error and complete are mutually exclusive terminal events
Dcomplete is called when the subscription is unsubscribed
The source completes without emitting anything. What happens with each?
javascript
source$.pipe(take(1)) // 0 or 1 values, always completes
source$.pipe(first()) // errors on an empty source
source$.pipe(first(null, 'n/a')) // …unless a default is suppliedAtake(1) completes silently; first() errors with EmptyError — unless given a default value
BBoth error
CBoth complete silently
Dtake(1) errors; first() completes silently
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.