I am trying to assign a callback function to a component variable... For example:
...
export class MyComponent {
private myCompVar: any;
myFunc = function(callback: (number) => void): void {
this.myCompVar = callback;
}
}
...and then later call this callback function from within another function in MyComponent. For instance:
...
export class MyComponent {
private myCompVar: any;
...
myOtherFunc(event): void {
...
this.myCompVar(callbackParam);
}
}
However, I am facing an issue where 'this.myCompVar' is undefined when attempting to call it inside 'myOtherFunc'. Despite setting the callback correctly in 'myFunc' and confirming its type as 'function', I encounter this error. 'myOtherFunc' is being called after 'myFunc', as expected.
Any assistance on this matter would be highly appreciated!