-2

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??

i.s.n raju
  • 15
  • 5

2 Answers2

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);
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