My component defines a method that receive a callback as a parameter
sendDeleteRequest(btn: MatButton, cbk: any) {
cbk()()
}
f() {
console.log(this.owner)
}
The callback is passed from the component template
<button mat-raised-button (click)="sendDeleteRequest(deleteCredBtn, f)" color="warn" #deleteCredBtn="matButton">Delete</button>
However the f function will raise a ERROR TypeError: this is undefined.
How can I preserve the context?
What I tried
- Saving
thisin aselfvariable inside theffunction to printself.owner - Returning a lambda function from
f - Using
bind(this)when invokingcbkfromsendDeleteRequest
None of them have worked.