I am fetching an object to typescript component , object contains different fields but my requirement is to read only one particular field in that object.how is it possible??
Asked
Active
Viewed 1,951 times
-2
-
Possible duplicate of [Access / process (nested) objects, arrays or JSON](https://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json) – str Jun 21 '18 at 10:05
-
yes, i implementing according to the document you shared. but it's not working – i.s.n raju Jun 21 '18 at 10:34
-
You have to be more specific than "not working". – str Jun 21 '18 at 10:36
-
can you share the code, and expected output ? – Abdu Manas C A Jun 21 '18 at 10:38
-
@AbduManaz plz check my answer – i.s.n raju Jun 21 '18 at 10:51
-
@raju did you seen my answer? – Karnan Muthukumar Jul 03 '18 at 14:11
2 Answers
0
Looks like you are getting an array of Objects. You need to pick the first element of data and call the property on it.
this.obj=data[0];
this.y=this.obj;
console.log(this.y.name);

Shubham Singhal
- 147
- 12
-
-
-
Add console.log(data) and share that. Might be your data is not proper. – Shubham Singhal Jun 21 '18 at 12:08
-
for console.log(data) , the data coming properly. but entire object is coming. But my requirement is only one field in that object – i.s.n raju Jun 21 '18 at 12:12
-
-
[{"_id":"5b272f50797dcc0bf8bad590","name":"aa","mobile":"bb","idproofno":"cc","car_bike":"dd","flat":"108","block":"B","customer":"suri","dov":"2018-06-18"} – i.s.n raju Jun 21 '18 at 12:15
-
-
0
Here is an simple example you can modify your convenient,
public data = [{ "_id": "5b272f50797dcc0bf8bad590", "name": "aa", "mobile": "bb", "idproofno": "cc", "car_bike": "dd", "flat": "108", "block": "B", "customer": "suri", "dov": "2018-06-18" }];
constructor(){
for(let item of this.data){
console.log("Data->>",item.name);
//here you can get any like mobile, car_bike, flat, block, customer,
}
}
For Demo click here https://stackblitz.com/edit/angular-ccvul4

Karnan Muthukumar
- 1,843
- 1
- 8
- 15