[Document Viewer] viewDocument

Hi. I’m using the ionic Native plugin DocumentViewer for display a pdf file, and all working good

cordova.plugins.SitewaertsDocumentViewer.viewDocument(FilePath, 'application/pdf', options, this.onShow, this.onClose, this.onMissingApp, this.onError)

But when i’m try to change the page when the “onClose” event is fired,

private onClose(close){
    console.log("close template pdf ", close)
    //alert("close pdf")

    this.navCtrl.push(InputPage, {
      idT: this.global.Pratica.IdRigaServizio
    });
  }

i have this error

Error in Success callbackId: SitewaertsDocumentViewer791885985 : TypeError: undefined is not an object (evaluating 'this.navCtrl')
TypeError: undefined is not an object (evaluating 'this.navCtrl')

it turn me crazy !!!

Thank you for your help

I stumbled upon this problem recently and I just hope my answer will be any help for future reference. I solve this issue by binding ‘this’ to the callback function.

    this.documentViewer.viewDocument(
      <filePath>,
      'application/pdf',
      options,
      this.onShow.bind(this),
      this.onClose.bind(this),
      this.onMissingApp.bind(this),
      this.onError.bind(this)
    );

By doing this, ‘this’ can be used inside the callback function.

  onClose() {
    this.doSomething();
  }