0
0
Angularframework~10 mins

Why observables matter in Angular - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Observable class from RxJS.

Angular
import { [1] } from 'rxjs';
Drag options to blanks, or click blank then click option'
AObservable
BSubject
CSubscription
DObserver
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Observer instead of Observable
Using Subject instead of Observable
2fill in blank
medium

Complete the code to subscribe to an observable and log the emitted value.

Angular
myObservable.subscribe({ next: value => console.[1](value) });
Drag options to blanks, or click blank then click option'
Alog
Binfo
Cwarn
Derror
Attempts:
3 left
💡 Hint
Common Mistakes
Using console.error which is for errors
Using console.warn which shows warnings
3fill in blank
hard

Fix the error in the code to correctly create an observable that emits 'Hello'.

Angular
const hello$ = new Observable(observer => { observer.[1]('Hello'); observer.complete(); });
Drag options to blanks, or click blank then click option'
Aerror
Bnext
Csubscribe
Demit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'emit' which is not a method on observer
Using 'subscribe' which is for subscribing, not emitting
4fill in blank
hard

Fill both blanks to create an observable that emits numbers 1 to 3 and then completes.

Angular
const numbers$ = new Observable(observer => { observer.[1](1); observer.[1](2); observer.[1](3); observer.[2](); });
Drag options to blanks, or click blank then click option'
Anext
Berror
Ccomplete
Dsubscribe
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'error' instead of 'complete'
Using 'subscribe' instead of 'complete'
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each emitted value to its square if the value is greater than 2.

Angular
const squares = { [1]: [2] for [3] of values if [3] > 2 };
Drag options to blanks, or click blank then click option'
Avalue
Bvalue * value
Dval
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently
Not squaring the value correctly