Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting variables from a getOne function

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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;
}

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading