I am unable to access objects declared within a class in Typescript from functions. Here's what I have:
export class QUestions {
credentials:mysqlCredentials.MySQLCredentials;
sqlConnector:mysql.Mysql;
constructor() {
this.credentials = new mysqlCredentials.MySQLCredentials('192.168.249.139', 'dev', 'dev', 'test');
this.sqlConnector = new mysql.Mysql(this.credentials);
}
addQuestion(req, res) {
var q = ...<Lot of code over here> ;
this.sqlConnector.query(q, null); //Error shown for this line
res.send();
}
}
Error:
TypeError: Cannot call method 'query' of undefined
If the code is structured as shown above i.e. the sqlConnector variable is defined in the Typescript class, it throws the error. If I place the sqlConnector outside the Typescript class it works fine. I need to fix this as I need the sqlConnector object inside the class.
export class Questions {
credentials:mysqlCredentials.MySQLCredentials;
constructor() {
this.credentials = new mysqlCredentials.MySQLCredentials('192.168.249.139', 'dev', 'dev', 'test');
sqlConnector = new mysql.Mysql(this.credentials);
}
addQuestion(req, res) {
var q = ...<Lot of code over here> ;
sqlConnector.query(q, null); //Error shown for this line
res.send();
}
}
var sqlConnector;