Complete the code to subscribe to the observable and log the data.
this.dataService.getData().[1](data => console.log(data));The subscribe method is used to listen to the observable and receive data.
Complete the code to handle errors when subscribing to the observable.
this.apiService.fetchItems().subscribe({ next: items => this.items = items, error: [1] });The error property expects a function to handle errors. Here, it logs the error.
Fix the error in the subscription to properly unsubscribe on component destroy.
subscription = this.service.getUpdates().[1](data => this.update(data));
ngOnDestroy() {
this.subscription.unsubscribe();
}Only subscribe returns a subscription object that can be unsubscribed.
Fill both blanks to subscribe to an observable and handle completion.
this.observable.[1]({ next: val => console.log(val), [2]: () => console.log('Complete') });
The subscribe method accepts an object with next, error, and complete handlers.
Fill all three blanks to subscribe with next, error, and complete handlers.
this.dataStream.[1]({ [2]: data => this.process(data), [3]: err => this.handleError(err), complete: () => this.finish() });
Use subscribe with an object containing next, error, and complete callbacks.
