Skip to content

Using signal inputs blows away context when passing a callback #63447

@jpike88

Description

@jpike88

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions