-
Notifications
You must be signed in to change notification settings - Fork 26.6k
Description
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
I used to be able to pass a component's function property as a callback to @input, and the context would be preserved (so using this
was safe).
Now, it appears that binding to inputs renders this
as undefined when I try to access it in the callback. So now code like this:
<custom-table [loadFilters]="getFilters"></custom-table>
I guess has to look the below to be equivalent.
<custom-table [loadFilters]="getFilters.bind(this)"></custom-table>
I can't overstate how frustrating this is both from a developer ergonomics and code safety perspective. Angular should be preserving the context of any function passed through as an input, for it to just blow it away makes zero sense.
I'm trying to migrate our codebase but this issue just made it go from already annoying to a total blocker. I would like to modernize things but not taking on crazy risk in doing so. It's impossible to audit our entire codebase for all uses of this
to compensate for such a change.
Please provide a link to a minimal reproduction of the bug
https://stackblitz.com/edit/wx8vh9ed?file=src%2Fmain.ts
Please provide the exception or error you saw
TypeError: undefined is not an object (evaluating 'this.x')
Please provide the environment you discovered this bug in (run ng version
)
20.2.0-next on stackblitz
Anything else?
No response