2017-03-26 4 views
1

Bluethooth接続が有効かどうかをチェックするコードを印刷しています。だから私はこれでした:私はこの持っている私の構築物へBluethoothSerial ionic 2から返品の約束を管理する

$ ionic plugin add cordova-plugin-bluetooth-serial 
$ npm install --save @ionic-native/bluetooth-serial 

を:

construnct(.... 
    private bluetoothSerial: BluetoothSerial, 
    .....){.. 
this.bluetoothSerial.isEnabled(/*here*/); 
...} 

今ここ

construnct(.... 
    private bluetoothSerial: BluetoothSerial, 
    .....){.. 

を私はbluethooth年代を有効または無場合メナージュする必要がありますか?

私はブール変数を作成し、そのブール値を有効または無効にするtrueまたはfalseを割り当てたいと思います。しかし、それを行う方法?

REF:

bluetoothSerial.isEnabled(
    function() { 
     console.log("Bluetooth is enabled"); 
     //myboolflag=true; dosen't work!!! 
    }, 
    function() { 
     console.log("Bluetooth is *not* enabled"); 
    } 
); 

here

答えて

2

あなたはこのように矢印の機能を使用する必要があります。矢印機能を使用することにより

bluetoothSerial.isEnabled(
    () => { 
     console.log("Bluetooth is enabled"); 
     this.myboolflag = true; // Should work now!!! 
    }, 
    () => { 
     console.log("Bluetooth is *not* enabled"); 
    } 
); 

thisプロパティが上書きされず、まだコンポーネントを参照しますインスタンス。

+0

このエラーが表示されます。**指定されたパラメータは、コールターゲットのシグネチャと一致しません。** –

+0

詳細を教えてください。または 'isEnabled'メソッドをどのように呼び出すべきですか? – sebaferreras

+0

男私はこのエラーがありました: - インラインテンプレート:0:43原因:BluetoothSerialのプロバイダがありません! –