Skip to content

UseCapture:true event handlers #11200

@davidTurczi

Description

@davidTurczi

I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[X ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
All events (click, keys, etc) are registered with a addEventListener(...,()=>{...},false) in the browser_adapter. If we want to "cancel" them ahead, by capturing the event and calling stopPropagation(), we have to use a non-angular native JS.

element.nativeElement.addEventListener('click', (event: MouseEvent) => {
            if (someCondition)
                event.stopImmediatePropagation();
        }, true);

Desired behavior
A way to add a handler to an element that adds the event listener to the capture phase. I leave the syntax to you, but something like @HostListener('~click',['$event']) seems logical to me (and similarly (~click)="...").

What is the motivation / use case for changing the behavior?
Creating directives that disables clicks/key events/etc. If the element has a custom handler on it, we need to cancel the event BEFORE it gets there.

Please tell us about your environment:

  • Angular version: 2.0.0-rc.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: coreIssues related to the framework runtimecore: event listenersfeatureLabel used to distinguish feature request from other issuesfeature: under considerationFeature request for which voting has completed and the request is now under considerationfreq1: low

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions