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
  • 48,608
  • 13
  • 72
  • 95
Rashid
  • 1,700
  • 1
  • 23
  • 56

0 Answers0