0
Ionic2 앱에서 블루투스 시리얼을 사용하고 있으며 연결할 수있는 장치를 나열하고 싶습니다.ionic2의 블루투스 시리얼, 장치 목록 없음
.ts 파일에서 지금 가져 왔지만 작동하지 않습니다. 블루투스를 사용할 수 있지만 목록을 볼 수없는 경우 목록을 볼 수 없습니다.
import { Component } from '@angular/core';
import { Platform, AlertController } from 'ionic-angular';
import { BluetoothSerial } from 'ionic-native';
import { NavController } from 'ionic-angular';
@Component({
selector: 'page-page1',
templateUrl: 'page1.html'
})
export class Page1 {
public working:string;
public var2: string ;
public lists = [];
constructor(private alertCtrl: AlertController, public platform: Platform, public navCtrl: NavController) {
platform.ready().then(() => {
BluetoothSerial.isConnected()
.then(() => {
console.log('is connected');
}, (err) => {
console.log(' not connected')
})
});
}
enableBluetooth(){
BluetoothSerial.enable()
}
discoverBluetooth(){
/* BluetoothSerial.setDeviceDiscoveredListener(function(device) {
console.log('Found: '+device.id);
});*/
}
unpairedBluetooth(){
BluetoothSerial.discoverUnpaired().then(function(devices) {
devices.forEach(function(device) {
console.log(device.id)});
})
}
listDevices(){
BluetoothSerial.isEnabled().then((data)=> {
console.log(data);
BluetoothSerial.list().then((allDevices) => {
this.lists = allDevices;
let result = [];
for (var key in this.lists) {
result.push(key);}
})
})}}
그리고 .html 파일에서 나는 몇 가지 목록을 표시하려고했지만이 중 아무 것도 작동하지 않습니다.
<ion-content padding>
<ion-buttons>
<button ion-button (click) = "enableBluetooth()">Enable!</button>
</ion-buttons>
<ion-buttons>
<button ion-button (click) = "listDevices()">List devices</button>
</ion-buttons>
Lijst1
<ion-list>
<ion-item *ngFor="let list of lists">{{list.devices}}</ion-item>
</ion-list>
Lijst2
<ion-list>
<ion-item *ngFor="let list of lists">{{list.device}}</ion-item>
</ion-list>
Lijst3
<ion-list>
<ion-item *ngFor="let list of lists">{{list.allDevices}}</ion-item>
</ion-list>
Lijst4
<ion-list>
<ion-item *ngFor="let key of lists">{{list.allDevices}}</ion-item>
</ion-list>
Lijst5
<ion-list>
<ion-item *ngFor="let key of lists">{{key}}</ion-item>
</ion-list>
Lijst
<ion-list>
<ion-item *ngFor="let list of lists">{{list}}</ion-item>
</ion-list>
<ion-buttons>
<button ion-button (click) = "unpairedBluetooth()">Unpair</button>
</ion-buttons>
</ion-content>