1

I am not sure what I am trying to do has any logic yet giving it a try.

I am trying to add Veriff SDK in my Angular App. The following error I get. Any help appreciated.

the .html

<button class="btn" [disabled]="isVerified"
                    (click)="myFn()">Finish</button>

The .ts file

export class myComponent(){
   isVerified : boolean = true;

ngOnInit() {

  const veriff = Veriff({
      host: 'https://stationapi.veriff.com',
      apiKey: '',
      parentId: 'veriff-root',
      onSession: function(err, response) {
        console.log(response.status)  //success
      window.veriffSDK.createVeriffFrame({ url: response.verification.url }); 
      if( response && response.status === 'success'){
        this.isVerified = !this.isVerified
      }
.....} //rest of the code is here

On ngOnInit() I call the Veriff api.

I am trying if response is success make disable false. But I am getting this Cannot read property 'isVerified' of undefined. How to fix this.

codejs
  • 141
  • 1
  • 10
  • Use an arrow function to preserve the meaning of `this` to the outer scope: `onSession: (err, response) => { ... }`. – ruth Jun 09 '21 at 10:42
  • this worked! Can't imagine coding life without stack overflow! Thank you!. – codejs Jun 09 '21 at 10:48
  • Can you share the steps you took to configure Veriff with Angular ? I am having an issue trying to integrate it. – Illep Jan 02 '23 at 07:38

1 Answers1

2

You have to use arrow functions (lambda expressions). Otherwise if you use functions it will change the meaning of this.

This should fix your issue:

ngOnInit() {

  const veriff = Veriff({
      host: 'https://stationapi.veriff.com',
      apiKey: '',
      parentId: 'veriff-root',
      onSession: (err, response) => {
        console.log(response.status)  //success
      window.veriffSDK.createVeriffFrame({ url: response.verification.url }); 
      if( response && response.status === 'success'){
        this.isVerified = !this.isVerified
      }
.....} //rest of the code is here
Michael Kang
  • 52,003
  • 16
  • 103
  • 135