【发布时间】:2017-06-17 09:53:01
【问题描述】:
当我扫描 BLE 设备时,会找到它们,但是,在找到它们之后,我会尝试将这些设备添加到列表中。
问题:应用程序上未显示列表(或为空)。
JS:
import { Component } from '@angular/core';
import { BLE } from '@ionic-native/ble';
@Component({
selector: 'page-about',
templateUrl: 'about.html'
})
export class AboutPage {
device_list: any[];
constructor(public alertCtrl: AlertController, public ble: BLE) {
}
scan(){
this.device_list = [];
this.ble.scan([], 5).subscribe(device => {
// ADDING TO LIST
this.device_list.push(device);
}, error => {
console.log('Check your bluetooth connection.');
});
}
}
如果我使用console.log(JSON.stringify(device)) 而不是this.device_list.push(device),则设备将被打印出来,但我需要将它们添加到列表中并在应用程序上显示该列表。
为什么会这样?
HTML:
<ion-header>
<ion-navbar>
<ion-title>
About
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<button ion-button (click)="scan()" color="danger" block>SCAN</button>
<ion-list>
<ion-item *ngFor="let item of device_list">
{{item.id+"----"item.name}}
</ion-item>
</ion-list>
</ion-content>
【问题讨论】:
-
好的,很明显,列表很好,里面有设备。但是,列表仅在以下情况下显示(更新):我切换到另一个选项卡并返回此选项卡(包含列表)或我切换到另一个应用程序并返回此应用程序如何解决此问题?
标签: javascript angular ionic-framework bluetooth bluetooth-lowenergy