Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Zone.js patch DOM on-event handler will failed with inline event handler. #525

@JiaLiPassion

Description

@JiaLiPassion

I will describe the problem with the sample code

<html>
<head>
</head>
<script src="./zone.js"> </script>
<script>
    function loaded() {
        var btn = document.getElementById('btn');
        console.log('btn click event handler', btn.onclick);
    }

    function btnClick(e) {
        console.log('clicked', e);
    }

    function blur() {
        console.log('blur', e);
    }
</script>
<body onload="loaded();">
    <input id="txt" type="text" onblur="blur();"/>
    <button type="button" id="btn" onclick="btnClick(event);">OK</button>
</body>
</html>

after zone.js patched, the button's onclick will be null, if without zone.js patched, the onclick will be btnClick, the problem only occurs when I use inline event handler like above, if I use

    btn.onclick = btnClick;

or

   btn.addEventListener(btnClick);

the result will be ok.

It seems not the problem of Zone.js itself but the DOM defineProperty.
https://github.com/angular/zone.js/blob/master/lib/common/utils.ts#L69
it seems after definePRoperty, the set will not be called when we use inline event handler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions