An observable represents a sequence of values produced over time. In Angular, RxJS provides the Observable<T> class; T identifies the type of each value. An Observable<string>, for example, produces string values. Unlike a Promise, which represents a single result, an observable can provide ongoing notifications. section 10.5.1
Call subscribe to respond when values arrive instead of repeatedly checking for them. A subscription can handle each new value, an error, and the end of the sequence. If only values matter, pass subscribe a single function. section 10.5.1
Table 10.5. The Observable<T> subscribe argument properties
|
Name
|
Description
|
|
next
|
This function is invoked when a new value is produced.
|
|
error
|
This function is invoked when an error occurs.
|
|
complete
|
This function is invoked when the sequence of values ends.
|
Use the subscribe handler table to choose between next, error, and complete callbacks. section 10.5.1
A value every 500 milliseconds
A Ticker exposes value: Observable<number> = interval(500). A component subscribes and assigns each received number to tickerValue, which its template displays. section 10.5.1
Observables also connect to several Angular APIs:
- HttpClient returns observable results for HTTP requests. An order repository can preserve Observable<Order> when it delegates saving to a REST data source. section 23.8 section 6.6.1
- A FormControl’s valueChanges emits control values. Set updateOn to blur when changes should be emitted after the input loses focus rather than on the default change event. section 21.3.1
- A QueryList’s changes observable notifies a directive when matching content children change. Subscribe after content initialization, when the query property is available. section 15.4.2
When the rest of an application expects a signal, toSignal converts an observable into one. For example, a product repository converts its REST data source’s products observable into a Signal<Product[]> with an initial empty array. section 6.6.1




