EventManager

An injectable service that provides event management for Angular through a browser plug-in.

class EventManager { constructor(plugins: EventManagerPlugin[], _zone: NgZone) addEventListener(element: HTMLElement, eventName: string, handler: Function): Function addGlobalEventListener(target: string, eventName: string, handler: Function): Function getZone(): NgZone }

构造函数

Initializes an instance of the event-manager service.

constructor(plugins: EventManagerPlugin[], _zone: NgZone)

参数

plugins

Type: EventManagerPlugin[].

_zone

Type: NgZone.

方法

Registers a handler for a specific element and event.

addEventListener(element: HTMLElement, eventName: string, handler: Function): Function

参数

element

The HTML element to receive event notifications.

eventName

The name of the event to listen for.

handler

A function to call when the notification occurs. Receives the event object as an argument.

返回值

Function: A callback function that can be used to remove the handler.

Registers a global handler for an event in a target view.

addGlobalEventListener(target: string, eventName: string, handler: Function): Function

参数

target

A target for global event notifications. One of "window", "document", or "body".

eventName

The name of the event to listen for.

handler

A function to call when the notification occurs. Receives the event object as an argument.

返回值

Function: A callback function that can be used to remove the handler.

Retrieves the compilation zone in which event listeners are registered.

getZone(): NgZone

参数

没有参数。

返回值

NgZone

注解

@Injectable()