Fernanda Luiz Pinto
Fernanda Luiz Pinto

Reputation: 103

using qr code to open an internal page in ionic 2

I'm new in ionic 2 and cordova development and I'm testing the cordova plugin "barcode scanner" to see what I can do with it. I wanna use the plugin to read a QR code that contains the link from a internal page in my app and then open this page.

I tried with this.navCtrl.push, but I don´t know why it didnt worked. Here's my code:

       click(){
         this.barcodeScanner.scan().then((barcodeData) => {
           this.navCtrl.push(barcodeData.text, data);
         }, (err) => {
              alert('Error');
         });
       }

Thanks in advance.

Upvotes: 0

Views: 918

Answers (1)

cantona_7
cantona_7

Reputation: 1177

Install this plugin at first.,

$ ionic plugin add phonegap-plugin-barcodescanner

$ npm install --save @ionic-native/barcode-scanner

you can import it from

"import { BarcodeScanner } from '@ionic-native/barcode-scanner';"

Then create a click button something like "scan" in .html and code this in .ts file

click() {
BarcodeScanner.scan()
.then((result) => {
if (!result.cancelled) {
      const barcodeData = new BarcodeData(result.text, result.format);
      this.scanDetails(barcodeData);
    }
  })
  .catch((err) => {
   alert(err);
  })
 }

Now just feed the link which you need to open in QRcode and scan it..

Upvotes: 1

Related Questions