Sitelet https://github.com/angular/angular/issues/30278
Skip to content

bug(compiler): this.$event and this.$any() should not be allowed in template聽#30278

Description

@trotyl

馃悶 bug report

Affected Package

The issue is caused by package @angular/compiler

Is this a regression?

No

Description

Currently $event and $any are treated as property read of ImplicitReceiver(this), and expanded to this.$event/this.$any by parser. Which means that user could manually write this.$event to access to $event object.

So the the following code are totally valid:

<button (click)="onClick(this.$any(this.$event))">Click Me!</button>

It's a really terrible pattern in template usage, gives the impression that these magical properties being assigned to component instance.

Instead, the parser should treat them as lexical identifier in the first place and forbid this. usage. It also applies to template reference.

馃敩 Minimal Reproduction

https://stackblitz.com/edit/angular-mgjryy?file=src%2Fapp%2Fapp.component.html

馃敟 Exception or Error

N/A

馃實 Your Environment

Angular Version:

7.2.5 now but doesn't matter

Anything else relevant?

This should be easy to implement once #30277 landed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions