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

Event handler return value #25269

Closed
pauldraper opened this issue Aug 2, 2018 · 3 comments
Closed

Event handler return value #25269

pauldraper opened this issue Aug 2, 2018 · 3 comments
Labels
area: core Issues related to the framework runtime
Milestone

Comments

@pauldraper
Copy link
Contributor

pauldraper commented Aug 2, 2018

The following link in HTML works

<a href="https://example.com" onclick="menuVisible = false">

However, the following link in an Angular template does not.

<a href="https://example.com" (click)="menuVisible = false">

Angular uses the last statement in the handler as the return value.

This behavior is undocumented, inconsistent with HTML, surprising, and I suspect usually unintentional. I would consider it a bug.

--

If you want to prevent default browser behavior, it should be

<a href="https://example.com" onclick="return menuVisible = false">
<a href="https://example.com" (click)="return menuVisible = false">
@kara kara added flag: can be closed? area: core Issues related to the framework runtime labels Aug 2, 2018
@ngbot ngbot bot modified the milestone: needsTriage Aug 2, 2018
@mhevery
Copy link
Contributor

mhevery commented Aug 2, 2018

The return statement is implied in all angular statements. So this is intentional, since we are not planning on adding return statement to our vocabulary.

@mhevery mhevery closed this as completed Aug 2, 2018
@pauldraper
Copy link
Contributor Author

pauldraper commented Aug 3, 2018

I still disagree that it is the wrong thing to behave so much differently than vanilla HTML. FWIW, angular-dart gave up this feature angulardart/angular#387

But at least this behavior should be documented?

@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 Sep 13, 2019
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
Projects
None yet
Development

No branches or pull requests

3 participants