2017-06-15 23 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

回答

相關問題