Câu hỏi phỏng vấn Angular
Câu hỏi

What is an Observer ?

Câu trả lời

An Observer in the context of Angular and RxJS is an interface that represents a consumer of push-based notifications delivered by an Observable. It is essentially a set of callback methods that define how to handle the data or events received from an Observable. These callback methods include:

  • next: This method is called to deliver the next value from the Observable. It is invoked whenever the Observable emits a new piece of data.
  • error: This method is called when the Observable encounters an error condition. It handles any errors that occur during the Observable execution.
  • complete: This method is called when the Observable successfully completes its sequence of data emissions.

Here is a basic structure of an Observer:

javascript Copy
interface Observer<T> {
  next: (value: T) => void;
  error: (err: any) => void;
  complete: () => void;
}

When subscribing to an Observable, you can pass an Observer to handle the data, errors, and completion notifications. For example:

javascript Copy
const myObservable = new Observable(subscriber => {
  subsc...
junior

junior

Gợi ý câu hỏi phỏng vấn

expert

Why Angular uses Url segment?

middle

What are Custom elements?

entry

What is Routing Guard in Angular?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào