简体   繁体   中英

retrieve data from a table in a json feed Angular 4

I have a function that returns this result:

    {id: 20, dateCreation: 1517324655450, auteurCreation: "bel", dateModification: 1530544886148, auteurModification: "user", …}
    auteurCreation:"bel"
    auteurModification:"user"
coupesTechniquesDescription:Array(1)
0:{id: 15, hauteurReference: 2, commentaireReference: "test"}
length:1
__proto__
:Array(0)
dateCreation:1517324655450
id:20

i want to save : coupesTechniquesDescription in a variable, the goal is to get the list of coupesTechniquesDescription and use the first index

Here you go. get the object right out of res :

// define the variable above your constructor
private coupesTechniquesDescription;

constructor(...){
    this.technicalservice.find(this.id).subscribe((res) => { 
        this.coupesTechniquesDescription = res.coupesTechniquesDescription[0];

        console.log(this.coupesTechniquesDescription);
    }, 
    (err) => { console.log("Erreur"); });

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM