Home > database >  Getting variables from a getOne function
Getting variables from a getOne function

Time:03-21

I am trying to get 2 variables (latitude and longitude) from data i have pulled from mongoDB. The data is console.logged as follows:

enter image description here

I am just trying to store the latidtude and longitude into their respective variables to be further manipulated.

this.getparamformid = this.route.snapshot.paramMap.get('facviewid');
    this.daformfacservice
      .getOneDAFacForm(this.getparamformid)
      .subscribe((daFormFac: DAFormFac[]) => {
        this.daformfacs = daFormFac;
        console.log(daFormFac, 'response of form');
        this.latitude =  daFormFac.latitude;
        this.longitude = daFormFac.longitude;

        console.log(this.latitude, this.longitude, "cords")
      });

the code above gets the data entry based on the _id and console logs the entire data entry console.log(daFormFac) However when trying to single out the latitude and longitude and save the data in variables it does not work.

this.latitude =  daFormFac.latitude;
this.longitude = daFormFac.longitude;

Am i doing this wrong?

interface for data entry:

export interface DAFormFac{
    _id: string;
    author: string;
    organizationName: string;
    eventName: string;
    eventDate: Date;
    area: string;
    areaCode: number;
    disasterNature: string;
    threatLevel: string;
    surroundingDamage: string;
    facilityName: string;
    latitude: Number;
    longitude: Number;
    facStatus: string;
    operEqu: Number;
    inoperEqu: Number;
    facilityDamage: string;
    facImage: string;
}

CodePudding user response:

this.daformfacservice
      .getOneDAFacForm(this.getparamformid)
      .subscribe((daFormFac: DAFormFac) => {
        this.daformfacs = daFormFac;
        console.log(daFormFac, 'response of form');
        this.latitude =  daFormFac['latitude'];
        this.longitude = daFormFac['longitude'];
      });

Try access the latitude and longitude as such

  • Related