Subject is a utility object in RxJS.

Subject is a special type of Observable that allows values to be multicast to many observers. Subject is like Eventemitters.

Each Subject is an Observable and an Observer. You can subscribe to a topic, and you can call the Next feed value as well as the error and completion.

This property is defined on the Popover Component:

The assignment takes place in the Popover Directive code:

When the Close button of the Popover Component is triggered by the mouse or keyboard, the registered Close event handler is triggered:

In the close event handler, the Subject broadcasts the CLOSE_BUTTON_CLICK or CLOSE_BUTTON_KEYDOWN event to its listener.

The Popover Directive defines all the events that trigger the Popover Component to shut down, as shown in the image above.

The Popover Directive is the listener for these events.

There are two problems here:

  1. When is HandlePopverEvents called by whom?
  2. Why is the Directive’s close function responsible for closing the Popover Component?

The Popover Directive’s EventSubject listens for events and assigns the EventSubject instance to the Component instance, which sends events:

Close operation:

If you comment out line 155 of the figure above, you will not be able to close the Popover Component:

More of Jerry’s original articles can be found on “Wang Zixi “: