title: Instascan QR Code scanner 'scan' listener won't update Angular 5 component view
body: <p>I've implemented Instascan (<a href="https://github.com/schmich/instascan" rel="nofollow noreferrer">https://github.com/schmich/instascan</a>) to allow users to read QR Codes from within my Angular 5 app.</p>
  
  <p>I have to trigger some actions after a successful scan and update my component's view accordingly.</p>
  
  <p>I'm using the following code inside my component to detect my cameras and start scanning:</p>
  
  <pre><code>cameras: Array&lt;any&gt; = []
  selectedCamera: any
  scanner: any
  content: string
  
  ngOnInit () {
      let vm = this
      Instascan.Camera.getCameras().then(function (cameras) {
        if (cameras.length &gt; 0) {
          vm.cameras.push(...cameras)
        } else {
          console.error('No cameras found.')
        }
      }).catch(function (e) {
        console.error(e)
      })
    }
  
  startScan () {
      let vm = this
      this.scanner = new Instascan.Scanner({
        video: this.videoContainer.nativeElement,
        backgroundScan: false,
        mirror: false
      })
      this.scanner.addListener('scan', function (content) {
        vm.content = content
      })
      this.selectedCamera = this.cameras[0]
      this.scanner.start(this.selectedCamera)
    }
  </code></pre>
  
  <p>And in my template I have an element that exists only if 'content' exists, and on click emit the scanned content to the parent component through an EventEmitter:</p>
  
  <pre><code>&lt;div *ngIf="content" class="btn" (click)="emitContent()"&gt;
            PROCEED
          &lt;/div&gt;
  </code></pre>
  
  <p>The problem is that in 'scan' event callback the changes in 'content' seems to don't be applied to my view, and my 'PROCEED' button don't become visible. An even stranger behavior happens: after I click anywhere in the screen, those changes are applied to my view.</p>
  
  <p>I've also tried using ChangeDetectorRef.detectChanges() method inside the callback and binding 'this' into the callback, but both are not working.</p>
  
  <p>How can I overcome this issue?</p>
  
  <p>Thanks!</p>