Skip to content

HostListener should have option to always run in ngZone #19878

@wizarrc

Description

@wizarrc

I'm submitting a...

[x] Feature request

Current behavior

@HostListener runs function in whatever zone it was in during creation

Expected behavior

@HostListener should allow an optional zone to be specified or a Boolean parameter to always run in NgZone

Alternately, provide zone creation context for component creators such as NgForOf. This may be easier to implement and more general purpose.

Minimal reproduction of the problem with instructions

Create component with a @HostListener event outside of NgZone. Every time that event is fired, it will be run in the zone it was created in.

What is the motivation / use case for changing the behavior?

Creating a virtual scroller and during creation of virtual components, the component's @HostListener's will register in the zone it was created in (not ngZone). It looks very ugly to have all events wrapped in zone.run functions. It would be nice to have a way to bind the function call to a particular zone declaratively.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4A relatively minor issue that is not relevant to core functionsarea: zonesIssues related to zone.jsfeatureLabel used to distinguish feature request from other issues

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions