0

I have this function inside my class which has Destructuring parameters

export default class MainCtrl {

    constructor(mainService ) {
        'ngInject';

        this.mainService = mainService;
    }

    $onInit() {
        navigator.geolocation.getCurrentPosition(this.search);
    }

    search({ coords }) {
        console.log(this); // shows undefined
        this.mainService.search(coords);
    }
}

Now when im using this.mainService it says this is always undefined. How to pass the this instance on this kind of function?

georgeawg
  • 47,985
  • 13
  • 70
  • 91
Rashid
  • 1,609
  • 19
  • 52

0 Answers0