Angular — Why you should (and how to) avoid Function.prototype.bind in template
3 min readOct 27, 2020
--
Function.prototype.bind
is a built-in function, which creates a new function with the context bound to the context given from the parameter. The major use case for this function in Angular template is the property binding (@Input
) of function.
<app-test-component
[testFunction]="printValue.bind(this)"></app-test-component>
This helps to maintain the context scope when the function is executed inside the component. It is a relatively uncommon function nowadays that some…