Buenas,
Tengo el siguiente 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"
}
]
}
Estoy tratando de trabajar con el en Angular 2 pero no tengo claro como poner la información del tempint o tempext en el modelo de datos.
Todo lo que he diseñado es mas básico y en el modelo de datos no se tiene que hacer referencia a esos dos objetos es algo mas simple.
export class Temp{
constructor(
public recvTime: string,
public attrName: string,
public attrValue: string
){}
}
Un saludo y gracias.
EDIT01
Estoy intentando utilizar la interfaz
interface MyData {
tempext: MyElem[];
tempint: MyElem[];
}
interface MyElem {
recvTime: string;
attrName: string;
attrValue: string;
}
pero a la hora de asignar a mi controller la interfaz no tengo claro como hacerlo.
Antes de tener los dos objetos y con la clase lo hacia de la siguiente forma: public mostrarfechaline(){
this._invService.getinvfechasensores(this.fecha3,this.fecha4).subscribe(
response => {
if (!response) {
console.log('error al cargar datos');
} else {
this.temp = response;
y así recuperaba todos los valores del campo:
var f0=this.temp.map(tempext => tempext.recvTime);
Como puedo hacer esto ahora?
así recupero el JSON completo del get en el servicio:
getinvfecha(fecha1,fecha2){
return this._http.get(this.url+'getinvfecha/'+fecha1+'/'+fecha2).map(res => res.json());
}
getInvFecha()
utiliza.map(res => <Temp[]>res.json()
. Lo has probado?. Luego en tuthis.temp = response;
, ya tendrías un arreglo (Temp[]
) conTempItem[]
en el interior de cada elemento.