I'm facing an issue with Ionic 2, specifically with Angular. My concern revolves around a variable called "isConnected". I am unable to access it from an internal function within a function as it gives me an error saying "can't define property of undefined". How can I successfully access my variable "isConnected" from an internal function? I attempted to use this: BleProvider.prototype.isConnected but to no avail. Could someone kindly explain to me how to make this work?
export class BleProvider {
public isConnected = false;
public mDevice;
constructor(public http: Http) {}
connectToDevice(device){
console.log('Connecting to device...');
this.mDevice = device;
setTimeout(
ble.connectToDevice(
device,
onConnected,
onDisconnected,
onConnectError),
500);
function onConnected(device) {
console.log("Connected to device: " + device.name);
this.isConnected = true;
console.log("isConnected variable status: " + this.isConnected);
}
function onDisconnected(device) {
console.log('Disconnected from device: ' + device.name);
}
function onConnectError(error) {
console.log('Connect error: ' + error);
}
}