Angular 4 - Code response value is undefined -




i loading data json file in html table,

this method in 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 method in service file:

getparticulars(){     return this._http.get(this.url).map(res => res.json()); } 

this 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, response service code (result.code) value undefined, don't know why?

console.log("code: ", result.code); 

if result code undefined, going access in condicion, when result code different 200, shows json file correct in console browser.

console.log("respuesta: ", result); 

thanks,

result array, should specifiy index,

console.log("code: ", result[0].code); 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -