#Binding functions in template - avoiding change detection
1 messages · Page 1 of 1 (latest)
how are you passing the function in
[passedFunction]="theFunction()"
</app-child-component>
.ts file
return () => doSomething()
}
So you're creating a new function at each change detection. Don't.
You're creating a new function on every change detection run, that's why it picks it up as a new value
right, that makes sense... any way i can retain this. binding without doing this?
Cheers!
Passing functions through @Input would never be something I recommend. I think that is a not great design and an anti-pattern
I have considered it briefly since I have't seen it done usually. But I'm not sure what alternative approach I would take. I have a 'mapping' function that gets passed in a table component otherwise the component is pretty much the same for a bunch of different data sets
Mapping in a table is one of the little use cases i have seen functions passed as inputs
Would still avoid if possible, but it does happen more often with tables.
I also need the 'raw type' (unmapped) in it since it gets passed to a detail component (legacy code I'm planning to update)
if you have shared small function, just export it