Issue
I'm creating a function inside the constructor, and it needs to be done inside the constructor, I wanted a button to activate it externally, however I have no idea how to do this.
My TypeScript
private functionActive;
constructor(){
this.functionActive = function hello(){
console.log('Hello world');
};
}
}
buttonActive(event){
this.functionActive.hello();
}
Solution
Two mistakes:
Define the function without the extra
)
constructor() { this.functionActive = function hello() { console.log("Hello world"); }; }
Invoke it using the reference of the function i.e.
functionActive
and nothello
, as it is a function expression:buttonActive(event) { this.functionActive(); }
Answered By - Nicholas Kurian
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.