Complete the code to create a simple observable that emits a single value.
import { Observable } from 'rxjs'; const obs = new Observable(observer => { observer.next([1]); observer.complete(); });
The next method sends a value to subscribers. Here, it emits the string 'Hello Observable!'.
Complete the code to create an observable from an array of numbers.
import { from } from 'rxjs'; const numbers = [1, 2, 3, 4]; const obs = [1](numbers);
The from function creates an observable from an array, emitting each item in sequence.
Fix the error in the observable creation to emit values 1, 2, and 3.
import { Observable } from 'rxjs'; const obs = new Observable(observer => { observer.next(1); observer.next(2); observer.next([1]); observer.complete(); });
The observable should emit the number 3 as the third value before completing.
Fill both blanks to create an observable that emits 'A' and 'B' using the correct creation function and method.
import { [1] } from 'rxjs'; const obs = [2]('A', 'B');
The of function creates an observable that emits each argument in order.
Fill both blanks to create an observable that emits the uppercase keys of an object if their values are true.
import { Observable } from 'rxjs'; const data = { a: true, b: false, c: true }; const obs = new Observable(observer => { for (const key in data) { if (data[key] [1] true) { observer.next(key[2]); } } observer.complete(); });
The observable emits keys whose values are exactly true, converting keys to uppercase before emitting.