Closed
Description
Which @angular/* package(s) are the source of the bug?
compiler, core
Is this a regression?
Yes
Description
We have components that render content in an ngFor
based on a structure such as
type ContentAndAdditionalData = {
content: string;
} & {
// Can be anything that somewhere has the correct value to track
};
where the items as well as the tracking function is passed through inputs.
This has been used like below with the old ngFor
syntax
@Input() items: Array<...>;
@Input() trackByFn: () => number;
---
*ngFor="let item of items; trackBy: trackByFn"
With the new @for
syntax, passing of a tracking function as an input is no longer possible as it yields the error
ERROR Error: trackByFn is not a function
when done like
<div>
@for(item of items; track trackByFn($index, item)) {
<span>{{ item.id }}</span>
}
</div>
This can be worked around by just tracking by reference as @for (item of items; track item)
but I would still expect that passing a tracking function as an input should work, or is it no longer possible?
Please provide a link to a minimal reproduction of the bug
Please provide the exception or error you saw
ERROR Error: trackByFn is not a function
Please provide the environment you discovered this bug in (run ng version
)
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 17.0.7
Node: 18.13.0
Package Manager: yarn 1.22.19
OS: darwin arm64
Angular: 17.0.7
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1700.7
@angular-devkit/build-angular 17.0.7
@angular-devkit/core 17.0.7
@angular-devkit/schematics 17.0.7
@schematics/angular 17.0.7
rxjs 7.8.1
typescript 5.2.2
zone.js 0.14.2
Anything else?
No response