Binding Angular Component Class Methods to This

Ole Ersoy
Ole Ersoy
Nov 2 · 1 min read
Image by Gerhard Gellinger from Pixabay

Scenario

We are using one of our Angular class methods bindMe as a callback. During the callback we will be accessing this .

Approach

Use bind .

this.bindMe = this.bindMe.bind(this);

Demo

In this demo we perform a callback to bindMe after two seconds:

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade