Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mat autocomplete input change event bleeds 'event' object #36035

Closed
KissBalazs opened this issue Mar 12, 2020 · 6 comments
Closed

Mat autocomplete input change event bleeds 'event' object #36035

KissBalazs opened this issue Mar 12, 2020 · 6 comments
Labels
area: core Issues related to the framework runtime core: event listeners freq2: medium
Milestone

Comments

@KissBalazs
Copy link

🐞 bug report

Affected Package

The issue is caused by package @angular/material 9.1.2

Is this a regression?

not sure.

Description

The event (change) will pass down an "event" object to the handler, even if it's not specified as a parameter.

🔬 Minimal Reproduction

https://stackblitz.com/edit/angular-x78zg6

see the autocomplete-overview-example.html lines 6-7, and their correspoding hander on autocomplete-verview-example.ts lines 65-72.

🔥 Exception or Error

console.log shows that we have an "event" object, although it is not defined in the function parameter list.

🌍 Your Environment

Angular Version:
see stackblitz dependencies.

@pkozlowski-opensource
Copy link
Member

After a quick scan it looks like a duplicate of #4059 where we've got a conflict between the (change) event on an <input> and the change event raised by a directive. Needs more investigation.

@pkozlowski-opensource pkozlowski-opensource added the area: core Issues related to the framework runtime label Mar 12, 2020
@ngbot ngbot bot added this to the needsTriage milestone Mar 12, 2020
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Mar 12, 2020
@KissBalazs
Copy link
Author

KissBalazs commented Mar 27, 2020

Might be connected to this issue, a button click handler also does the same thing:

<button (click)=handle()>...</button>

Also bleeds an "event" variable in handler:

public handle(){
   console.log(event); // this should not exist here, but does.
}

See this Stackblitz example.

@pkozlowski-opensource
Copy link
Member

@KissBalazs I'm sorry but it is not clear from your stackblitz what is the issue that you are trying to illustrate... Is it about "most of the time" this exists here."??? If you are unsure if your issue is different from the one discussed here, please open a new issue but follow the issue template when doing so (most importantly we need a reproduce scenario that shows broken / non-working scenario).

@KissBalazs
Copy link
Author

@pkozlowski-opensource sorry for the confusion, I have cleared up my comment.

@pkozlowski-opensource
Copy link
Member

@KissBalazs thnx for the additional clarifications! You are totally right to be confused as to why one can access event! It turns out, though, that it is not Angular specific but you are bumping into https://developer.mozilla.org/en-US/docs/Web/API/Window/event

The long story short that browsers will expose event (for the event being processed) on the window. Since window acts as a global in the browser environment, you can access it in your event handler. You would observe the same effect Angular or not.

Going to close this one as it is not specific to Angular but rather to how browsers work. But hey, totally see how this could be confusing!

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jun 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: core Issues related to the framework runtime core: event listeners freq2: medium
Projects
None yet
Development

No branches or pull requests

4 participants