2017-06-15 25 views
1

我的最终目标是建立一个应用程序,将有一个按钮,按下该按钮时:离子 - BluetoothSerial在构造函数中,使无形的所有元素

  1. 列表中的所有未配对的蓝牙设备-----(HC-的Arduino 06尤其是)
  2. 选择设备连接到
  3. WRITE数据到设备

首先,我是测试按钮的功能。

我的按钮是可见的,并显示按下它之后的警告:

HTML:

<ion-header> 
    <ion-navbar> 
    <ion-title> 
     About 
    </ion-title> 
    </ion-navbar> 

</ion-header> 

<ion-content padding> 
    <button ion-button ng-click="showAlert()">FIND</button> 
</ion-content> 

JS:

import { Component } from '@angular/core'; 
import { AlertController } from 'ionic-angular'; 

@Component({ 
    selector: 'page-about', 
    templateUrl: 'about.html' 
}) 

export class AboutPage { 

    constructor(public alertCtrl:AlertController) { 

    } 

    showAlert() { 
    let alert = this.alertCtrl.create({ 
     title: 'TEST TITLE', 
     subTitle: 'TEST SUBTITLE', 
     buttons: ['OK'] 
    }); 
    alert.present(); 
    } 

现在使用蓝牙,我需要包括BluetoothSerial在构造函数中,然而,该按钮包括它消失后:

JS:

import { Component } from '@angular/core'; 
import { AlertController } from 'ionic-angular'; 
import { BluetoothSerial } from '@ionic-native/bluetooth-serial'; 

@Component({ 
    selector: 'page-about', 
    templateUrl: 'about.html' 
}) 

export class AboutPage { 

    constructor(public alertCtrl:AlertController, 
       public bluetoothSerial: BluetoothSerial) { 

    } 

    showAlert() { 
    let alert = this.alertCtrl.create({ 
     title: 'TITLE HERE', 
     subTitle: 'RANDOM', 
     buttons: ['OK'] 
    }); 
    alert.present(); 
    } 

我测试这一切在Android设备上。

问题1:我该如何解决这个问题?

问题2:也许有人已经完成了这个整个应用程序,并可以分享他们的代码?

+0

当你说按钮消失,你的意思是这个按钮? ''。顺便说一句,你应该做'(click)=“showAlert()'而不是 – maninak

+0

是的,这个按钮。 我改成了'(click)=”showAlert()“',仍然出现错误 – aivarastee

+0

是的,无论如何,让我们来做标准的'离子平台去除android &&离子平台添加android',看看更新平台是否会做任何事情。 – maninak

回答

相关问题