私は現在、ライブラリBLE https://github.com/evothings/cordova-bleを使用してIonic 2でアプリケーションを開発中です。ここで知りたいのは、関数onConnectedを呼び出す関数ble.connectToDeviceを呼び出すconnectToDevice関数です。関数onConnectedの中で、関数connectToDeviceの外部にある関数enableNotification(device)を呼び出したいと思います。しかし、私はエラーが発生します:TypeError:_this.enableCoinNotificationは関数ではありません。イオン2の内部機能と外部機能
誰かがこの問題を解決し、それを私に説明できますか?
export class BleProvider {
constructor(){
this.connectToDevice(device)
}
connectToDevice(device){
let onConnected = (device) => {
console.log("Connected to device: " + device.name);
return startNotifications(device);
},
onDisconnected = (device) => {
console.log('Disconnected from device: ' + device.name);
},
onConnectError = (error) => {
console.log('Connect error: ' + error);
};
setTimeout(() => {
ble.connectToDevice(
device,
onConnected,
onDisconnected,
onConnectError)
}, 500);
let startNotifications = (device) => {
console.log("Start Notification called");
this.enableCoinNotification(device) // ERROR : TypeError: _this.enableCoinNotification is not a function
};
}
enableCoinNotification(device){
let onNotificationSuccess = (data) =>{
console.log('characteristic data: ' + ble.fromUtf8(data));
},
onNotificationError = (error) =>{
};
ble.enableNotification(
device,
this.coinEventNotificationUUID,
onNotificationSuccess,
onNotificationError)
}
}
どのように 'connectToDevice'を呼びますか? – Nirus
私はコンストラクタでそれを呼び出すことができます。コード – Junior
を編集しました。 – Nirus