Angular — Why you should (and how to) avoid Function.prototype.bind in template

Liu Ting Chun
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…

--

--

Liu Ting Chun

Web developer from Hong Kong. Most interested in Angular and Vue. Currently working on a Nuxt.js + NestJS project.