0

I have this constructor function buy I need to take out the value of lat1,lat2,lon1,lon2 from the constructor to use the constant out off the constructor

export class MapasPage {
  map: any;
  markers:any;
  //datos
  contacts: ContactList[];
  Latitud:any;
  Longitud:any;
  Lat1:any;
  Lon1:any;
  Lat2:any;
  Lon2:any;

  
 constructor(public navCtrl: NavController, public geolocation: Geolocation, public platform:Platform,private contactProvider: ContactProvider) {
        ///datos
        this.contactProvider.getAll()
        .then((result) => {
          this.contacts = result;
          
          let answer = this.contacts.map(x=> {
          let {name2, name3} = x.contact;
          let obj = {name2,name3}
          return obj
          })
          this.Latitud= answer.map(({ name2}) => name2);
          this.Longitud= answer.map(({ name3}) => name3);
         // console.log(answer)
          this.Lat1=this.Latitud[0];
          this.Lat2=this.Latitud[1];
          this.Lon1=this.Longitud[0];
          this.Lon2=this.Longitud[1];
         // console.log(this.Lat1)
          
      }) 
    } 
  • 2
    Possible duplicate of [Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference](https://stackoverflow.com/questions/23667086/why-is-my-variable-unaltered-after-i-modify-it-inside-of-a-function-asynchron) – T.J. Crowder Aug 29 '18 at 17:37
  • ...and/or http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call. – T.J. Crowder Aug 29 '18 at 17:37
  • 2
    Your code *does* add `Lat1` and such properties on the instance you're constructing, but it does so *asynchronously*. – T.J. Crowder Aug 29 '18 at 17:38

0 Answers0