Good morning,
I have the following JSON:
{
"tempext": [
{
"attrName": "tempext",
"attrValue": "17.054.495",
"recvTime": "2017-11-26T18:45:00.000Z"
},
{
"attrName": "tempext",
"attrValue": "17.054.495",
"recvTime": "2017-11-26T18:45:00.000Z"
}
],
"tempint": [
{
"attrName": "tempint",
"attrValue": "19.018.230",
"recvTime": "2017-11-26T18:45:00.000Z"
},
{
"attrName": "tempint",
"attrValue": "28.634.987",
"recvTime": "2017-10-24T12:00:00.000Z"
}
]
}
I'm trying to work with him in Angular 2 but I'm not sure how to put the tempint or tempext information in the data model.
Everything I have designed is more basic and in the data model you do not have to make reference to those two objects, it's something simpler.
export class Temp{
constructor(
public recvTime: string,
public attrName: string,
public attrValue: string
){}
}
Greetings and thanks.
EDIT01
I'm trying to use the interface
interface MyData {
tempext: MyElem[];
tempint: MyElem[];
}
interface MyElem {
recvTime: string;
attrName: string;
attrValue: string;
}
but when it comes to assigning the interface to my controller, I'm not sure how to do it.
Before having the two objects and with the class, I did it in the following way: public mostrarfechaline () {
this._invService.getinvfechasensores(this.fecha3,this.fecha4).subscribe(
response => {
if (!response) {
console.log('error al cargar datos');
} else {
this.temp = response;
and thus it recovered all the values of the field:
var f0=this.temp.map(tempext => tempext.recvTime);
How can I do this now?
this way I recover the complete JSON of the get in the service:
getinvfecha(fecha1,fecha2){
return this._http.get(this.url+'getinvfecha/'+fecha1+'/'+fecha2).map(res => res.json());
}