# How to implement a QR Scanner in Ionic 4? Camera not showing

**URL:** <https://forum.ionicframework.com/t/how-to-implement-a-qr-scanner-in-ionic-4-camera-not-showing/185331>\
**Category:** Ionic Angular\
**Created:** [March 17, 2020, 9:52pm UTC](https://forum.ionicframework.com/t/how-to-implement-a-qr-scanner-in-ionic-4-camera-not-showing/185331 "2020-03-17T21:52:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![feliperiverot](https://avatars.discourse-cdn.com/v4/letter/f/9f8e36/32.png) [@feliperiverot](https://forum.ionicframework.com/u/feliperiverot)\
**Post date:** [March 17, 2020, 9:52pm UTC](https://forum.ionicframework.com/t/how-to-implement-a-qr-scanner-in-ionic-4-camera-not-showing/185331/1 "2020-03-17T21:52:21Z")

</div>

I am working with ionic 4 developing and app. I installed the [cordova QR Scanner plugin](https://ionicframework.com/docs/native/qr-scanner), because I need the QR functionality

I followed the tutorial, but the camera is not showing. here is the ts script:

```auto
import { Component, OnInit } from '@angular/core';
import { ModalController } from '@ionic/angular';
import { QRScanner, QRScannerStatus } from '@ionic-native/qr-scanner/ngx';

@Component({
  selector: 'app-agregarpin',
  templateUrl: './agregarpin.page.html',
  styleUrls: ['./agregarpin.page.scss'],
})
export class AgregarpinPage implements OnInit {

  constructor(public modalController: ModalController,private qrScanner: QRScanner) { }

  ngOnInit() {
  }

    dismiss() {
    // using the injected ModalController this page
    // can "dismiss" itself and optionally pass back data

    this.modalController.dismiss();
  }

  scandata(){

      this.qrScanner.prepare()
  .then((status: QRScannerStatus) => {

     if (status.authorized) {
       // camera permission was granted

        this.qrScanner.show();
       // start scanning
       let scanSub = this.qrScanner.scan().subscribe((text: string) => {
         console.log('Scanned something', text);

         this.qrScanner.hide(); // hide camera preview
         scanSub.unsubscribe(); // stop scanning
       });

     } else if (status.denied) {

       // camera permission was permanently denied
       // you must use QRScanner.openSettings() method to guide the user to the settings page
       // then they can grant the permission from there
     } else {
       // permission was denied, but not permanently. You can ask for permission again at a later time.
     }
  })
  .catch((e: any) => console.log('Error is', e));

  }//

}

```

After some tested I didn’t found any error. After some researched I got this, the camera is working but under app. The layers and html tags are above the camera. Then I follow this [tutorial](https://softwarb.blog/ionic-qr-scanner/), and the camera still is not showing.

The fix according to the tutorial and others forum is to add a css class to ion-app tag, like this:

CCS

```auto
ion-app.cameraView, ion-app.cameraView ion-content, ion-app.cameraView .nav-decor {
  background: transparent none !important; 
}

```

This css code, I added to global.scss and app.component.scss files.

And then is the updated function:

```auto
 scandata(){

        (window.document.querySelector('ion-app') as HTMLElement).classList.add('cameraView');
         (window.document.querySelector('body') as HTMLElement).classList.add('cameraView');
          (window.document.querySelector('ion-router-outlet') as HTMLElement).classList.add('cameraView');

      this.qrScanner.prepare()
  .then((status: QRScannerStatus) => {

     if (status.authorized) {
       // camera permission was granted

        this.qrScanner.show();
       // start scanning
       let scanSub = this.qrScanner.scan().subscribe((text: string) => {
         alert('Scanned something');

         this.qrScanner.hide(); // hide camera preview
         scanSub.unsubscribe(); // stop scanning
       });

     } else if (status.denied) {

       // camera permission was permanently denied
       // you must use QRScanner.openSettings() method to guide the user to the settings page
       // then they can grant the permission from there
     } else {
       // permission was denied, but not permanently. You can ask for permission again at a later time.
     }
  })
  .catch((e: any) => console.log('Error is', e));

  }//

```

But the camera still not showing here are some screenschots.

The page, is completely blank with only a button with the click function that calls the scandata() method [![enter image description here](https://global.discourse-cdn.com/ionicframework/original/3X/4/5/450c12ac55e13698a7e9738bbba61d2902805020.png)](https://i.stack.imgur.com/VmUnK.png)

When I clicked the “default” button A dialog box appears asking for permission to use the camera:

[![enter image description here](https://global.discourse-cdn.com/ionicframework/original/3X/e/a/eadd55c8f87b3bc2537bd4c958877b7df2d225c1.png)](https://i.stack.imgur.com/SgU8q.png)

I click on the “allow” button, but still the camera, is not working.

[![enter image description here](https://global.discourse-cdn.com/ionicframework/original/3X/4/5/450c12ac55e13698a7e9738bbba61d2902805020.png)](https://i.stack.imgur.com/VNn2n.png)

I dont know what else I can do.

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [March 17, 2020, 10:14pm UTC](https://forum.ionicframework.com/t/how-to-implement-a-qr-scanner-in-ionic-4-camera-not-showing/185331/2 "2020-03-17T22:14:38Z")

</div>

> [@feliperiverot](#):
>
> I dont know what else I can do.

What I did was switch to Capacitor and Barcode Scanner (which handles QR too).
