管理 BluethoothSerial ionic 2 的退货承诺

旅行疗法

我正在编写一个代码来检查蓝牙连接是否启用。所以我这样做了:

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

在我的构造中,我有这个:

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

现在在这里

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

我需要管理蓝牙是否启用?

我创建了一个布尔变量,我想将它分配为 true 或 false,这取决于蓝牙是否启用。但是怎么做呢?

裁判 :

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

这里

塞巴费雷拉斯

你应该使用这样的箭头函数:

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

通过使用箭头函数,this属性不会被覆盖并且仍然引用组件实例。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

对象承诺退货

Ionic 2-如何管理全局变量?

Ionic 2 / Angular 2中的承诺,怎么办?

在Angular 2,Ionic 2中返回承诺值

未抓到(承诺):Ionic 2中可用的cordova_not_available

AlertController Ionic 2未捕获(承诺):插入的视图已被破坏

“退货等待承诺”和“退货承诺”之间的区别

模块退货承诺到快递

RXJS 6中的退货承诺

如何管理多重承诺

管理承诺依赖

如何在ionic2 Web应用程序中管理多个滑块?

工厂已解决承诺的退货结果

获取已解决的承诺的退货类型?

Cordova(Ionic2)自定义插件:使用cordova.exec()successHandler管理Angular2新的Promise()

ionic 2服务命令错误:未捕获(按承诺):[object PositionError]

未捕获(承诺)TypeError:ionic2中的对象不是构造函数(…)

ionic 2地图加载“未捕获(承诺):[object PositionError]”

我无法在Ionic2上让我的课程成为一个承诺

在 RXJS observables 中管理承诺

在工厂内承诺,承诺完成前要退货

ionic2:如何在侧菜单中管理我们应用程序中的用户状态?

Ionic View管理应用程序

Cordova / Ionic插件管理的最佳做法?

Ionic2-运行时错误未捕获(在承诺中):错误:HTTP没有提供程序

Ionic2未处理的承诺拒绝:模板解析错误:'ion-item-content'不是已知元素:错误

承诺退货与React Native不一致

从承诺内部可以观察到的已解决的退货

Firestore 承诺在退货前等待产品详细信息