Function not found, but works in javascript


#1

Hi all,

Usually this would work in regular javascript but its causing an issue in ionic/typescript and I can’t figure out why.

Error: function not found -> this.DriverFound()

  DriverFound() {
    this.isPickupActivated = true;
  }

  RequestPickup() {
    console.log("Pickup requested");
    this.isPickupRequested = false;
    
    let loader = this.loadingCtrl.create({
      content: "Searching for driver. . .",
      duration: 3000
    });
    loader.present();
    setTimeout(function(){ this.DriverFound(); }, 3000);
  }

#2

this is different inside the setTimeout. Use an arrow function.


#3

I am always suspicious when I see setTimeout(). It’s virtually never the best idea.