Search code examples
ionic-frameworkcordova-pluginsinappbrowserionic5

Getting JSON Data from InAppBrowser IONIC 5


I'm using the cordova in-app-browser plugin. One Page I get back is just a bunch of JSON-Data which i want to store inside my IONIC 5 Project. I could'nt figure out yet how to receive the Data and transfer it to the App yet with the Plugin. Is there such a possibility?

Thank you


Solution

  • To transfer data using InAppBrowser you can pass It by parameters, and also to receive the date you get it from parameters. Follows a small example:

    Short way sending data on Page1.ts:

    const dataToSend = `/${this.dataOne}/${this.dataTwo}`;
    let finalUrl = `https://app-example.io` + dataToSend;
    this.inAppB.create(finalUrl, '_system');
    

    Receiving data on Page2.ts:

    import { ActivatedRoute } from '@angular/router';
    
    constructor(
        private actRoute: ActivatedRoute
    ){}
    
    ngOnInit() {
      this.actRoute.paramMap.subscribe( params => {
        console.log('Params => ', params);
        if (params) {
          let dataReceived = [params['params']['dataOne'], params['params']['dataTwo']];          
          console.log('dataReceived => ', dataReceived);
        }
      }
    }
    

    Please, adapt it to your code and variables as it is just a short example.