I am loading data from a json file in a html table,
This is the method in my component file:
getParticulars(){
this._particularService.getParticulars().subscribe(
result => {
console.log("code: ", result.code);
if(result.code != 200){
console.log("Respuesta: ", result);
}else{
console.log("Si tengo datos para particulares");
this.particulars = result.data;
}
},
error => {
console.log(<any>error);
}
);
}
This is the method in my service file:
getParticulars(){
return this._http.get(this.url).map(res => res.json());
}
This is the file json:
[
{
"code": "200"
},
{
"field1": "1",
"field2": "2",
"field3": "3",
"field4": "31/12/9999",
"field5": "4,
"field6": "5",
"field7": "7",
"field8": "8",
"field9": "9",
"field10": "10"
},
{
"field1": "11",
"field2": "12",
"field3": "11/07/2017",
"field4": "13",
"field5": "14",
"field6": "15",
"field7": "16",
"field8": "17",
"field9": "18",
"field10": "19"
}
]
The problem is, the response service code (result.code) value is undefined, but I don't know Why?
console.log("code: ", result.code);
If the result code is undefined, I am going to access in the condicion, when the result code is different to 200, but it shows the json file correct in console browser.
console.log("Respuesta: ", result);
Thanks,