BLE scan returns [Object object] instead of any devices


im trying to use the scan function to pick up devices. everything seems to work but it doesnt return anything. ive tried it on my phone through ionic view. but still returns [object object]

the goal is the data to be displayed in the alert message.


import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import {BLE} from '@ionic-native/ble';
import { AlertController } from 'ionic-angular';

  selector: 'page-home',
  templateUrl: 'home.html'
export class HomePage {

  devices: any;

  constructor(public alert: AlertController, public ble: BLE, public navCtrl: NavController) { }


  let notice = this.alert.create({
  title: 'devices found',
  message: this.devices,
  buttons: ['OK']


  this.devices = this.ble.scan([],5);


any help would be appreciated :slight_smile:


scan returns an Observable. Type this.devices to match it. As I said on another thread recently, you’ll help yourself a lot if you never declare a variable as any ever again. Then use Observable operators or a subscription to handle the values the Observable emits.


I am so happy not to be the only person tilting at this particular windmill. JavaScript is a horrendous language for many reasons, but TypeScript’s addition of compile-time type checking ameliorates a big one, and it is really short-sighted not to take advantage of it. Not only do you turn runtime bugs into compile-time bugs (which is a huge win in and of itself), but you get an opportunity to make your code self-documenting, which is a major benefit to whoever is trying to maintain it. That is likely to be you in the future.


what is a observer and how do i use/work with them can you provide xample code or atless what i should type into mine


Explanation of Overservables:

(@Sujan12 please consider putting this link in some kind of FAQ sticky. It seems as though there are a lot of new posters who have never heard of Observables.)