Display variable value from a Cordova plugin function/provider



I’m trying to display an ID I retrieve from a Cordova plugin in my Ionic 2 application. The problem is that I can display it in the console log but I cannot figure out how to display it in the Ionic view.

Service/Provider code

    let idNumber;

        idNumber = (success);
        console.log("Cannot retrieve Id. Please enable bluetooth.");
        this.androidPermissions.requestPermissions([this.androidPermissions.PERMISSION.BLUETOOTH, this.androidPermissions.PERMISSION.BLUETOOTH]);
        return idNumber;

Homepage.ts code

  ionViewDidLoad() {

Homepage.html code

<ion-content padding>
  <p>Device id: {{IdService.initiate}}</p>
  <button ion-button (click)="synchronize()"></button>

Help? :slight_smile:



I am completly new to ionic and web things. So it is only a guess.

All examples I saw used a variable or a property to display in {{bla}}. So don’t know if a function is working. Maybe you can try to use a property or variable.

Best regards, anna


Do you mean the Ionic View app by that?
If so: Ionic View only supports a limited amount of plugins listed here: https://docs.ionic.io/tools/view/#supported-plugins
To test your custom Cordova plugin you have to use ionic cordova run or a similar command to build your own app. (It’s not that difficult you once worked it out. Alternatively you can use Ionic Package to build in the cloud)


This is not going to work as you are trying to write it. It is impossible to synchronously return a value that is asynchronously generated.

If at all possible, please use the ionic-native shim for whatever this plugin is. Doing so will guide you naturally towards how to use the futures properly.


Sorry, to make it clear I mean the Ionic page rather than the Ionic View software haha. I’ve been testing on an actual device due to using my Cordova plugin.


I am using a native Android SDK for my Cordova plugin, therefore use of Ionic Native isn’t possible. The value of the ID is returned in the console.log so why can’t I display it on my Ionic page? Can you help?


I am new to all these things.
But I think you can bind only to property (variables). Have you tried to declare your idNumber outside of function and bind this

Device id: {{IdNumber}}

https://angular.io/guide/displaying-data (please, please be the correct angular)

Best regards, anna.


Hi Anna,

I’ve tried that too, it doesn’t work. I believe it has something to do with what @rapropos stated. I’m also new to Ionic but the Cordova plugin is the difficult part :sweat:


okay let’s try something else. Give your element an Id

<p id="pwork">This Device id will overwriten </p>
add then  after

(<HTMLParagraphElement> document.getElementById('pWork')).innerHTML = "Device Id: " + idNumber)
If innerHtml is not working you can try textcontent.

I use this in a similar case.

best regards, anna


My work colleague helped me figure it out. @rapropos was right. I needed to make my function a promise. So…
Service/Provider code


    return new Promise((resolve, reject) => {
        reject("Cannot retrieve Id. Please enable bluetooth.")
        console.log("Cannot retrieve Id. Please enable bluetooth.");


  ID: string;

  ionViewDidLoad() {

      this.ID= ID;
    }).catch(error => {


  <p>Device id: {{deviceId}} </p>