fix(zone.js): Make EventTarget
methods optional in zone.js
extension API (#35954)
`zone.js` added `removeAllListeners` and `eventListeners` methods in `EventTarget.prototype`, but those methods only exists when user import `zone.js` and also enables `EventTarget` monkey patching. If user: 1. Does not import `zone.js` and uses `noop` zone when bootstrapping Angular app. OR 2. Disable monkey patching of `EventTarget` patch by defining `__Zone_disable_EventTarget = true`. Then `removeAllListeners` and `eventListeners` methods will not be present. PR Close #35954
This commit is contained in:

committed by
Andrew Kushnir

parent
8456c5ec60
commit
54634628ac
@ -17,22 +17,28 @@ interface EventTarget {
|
||||
*
|
||||
* Remove all event listeners by name for this event target.
|
||||
*
|
||||
* This method is optional because it may not be available if you use `noop zone` when
|
||||
* bootstrapping Angular application or disable the `EventTarget` monkey patch by `zone.js`.
|
||||
*
|
||||
* If the `eventName` is provided, will remove event listeners of that name.
|
||||
* If the `eventName` is not provided, will remove all event listeners associated with
|
||||
* `EventTarget`.
|
||||
*
|
||||
* @param eventName the name of the event, such as `click`. This parameter is optional.
|
||||
*/
|
||||
removeAllListeners(eventName?: string): void;
|
||||
removeAllListeners?(eventName?: string): void;
|
||||
/**
|
||||
*
|
||||
* Retrieve all event listeners by name.
|
||||
*
|
||||
* This method is optional because it may not be available if you use `noop zone` when
|
||||
* bootstrapping Angular application or disable the `EventTarget` monkey patch by `zone.js`.
|
||||
*
|
||||
* If the `eventName` is provided, will return an array of event handlers or event listener
|
||||
* objects of the given event.
|
||||
* If the `eventName` is not provided, will return all listeners.
|
||||
*
|
||||
* @param eventName the name of the event, such as click. This parameter is optional.
|
||||
*/
|
||||
eventListeners(eventName?: string): EventListenerOrEventListenerObject[];
|
||||
eventListeners?(eventName?: string): EventListenerOrEventListenerObject[];
|
||||
}
|
||||
|
Reference in New Issue
Block a user