-
Notifications
You must be signed in to change notification settings - Fork 26.2k
feat(compiler): support arrow function in template #30277
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 8000 occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
]); | ||
}); | ||
|
||
it('should parse bound events and properties via [(...)]', () => { | ||
expectFromHtml('<div [(prop)]="v"></div>').toEqual([ | ||
['Element', 'div'], | ||
['BoundAttribute', BindingType.Property, 'prop', 'v'], | ||
['BoundEvent', 'propChange', null, 'v = $event'], | ||
['BoundEvent', 'propChange', null, 'this.v = this.$event'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't be surprise, this is really the normalized form in parser, which already works in template:
<button (click)="onClick(this.$any(this.$event))">Click Me</button>
https://stackblitz.com/edit/angular-mgjryy?file=src%2Fapp%2Fapp.component.html
@@ -80,7 +79,9 @@ class Unparser implements AstVisitor { | |||
this._expression += ')'; | |||
} | |||
|
|||
visitImplicitReceiver(ast: ImplicitReceiver, context: any) {} | |||
visitImplicitReceiver(ast: ImplicitReceiver, context: any) { this._expression += 'this'; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Showing this now to recognize component property against lexical identifier.
96dc4a2
to
3670f82
Compare
3670f82
to
5f362d9
Compare
This is a feature which we very much would like to have. The current PR only solves the syntax for the ViewEngine but not for Ivy. It also does not account for corner cases of containing closure over other variables. So even thought we would very much like this it would take quite a lot of work to get it over the finish line. We will have to implement this with those constraints in mind. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
closes #14129
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #14129
Suggested by @mhevery in #12969 (comment).
What is the new behavior?
Arrow functions are now supported in template expression, like:
Restrictions from JavaScript syntax:
Does this PR introduce a breaking change?
Other information