How to get value from the below JSON array in angular?




Asked on September 01, 2019
Hello,

Please find below JSON object, I am new in Angular and I need to know how we can get the value (with bold) for below JSON report. I wan't to make input type and button (using "id" in red color) in payment array and result with the bold value.

=== JSON ===
{
  "success": 1,
  "object": "list",
  "total_count": 2,
  "data": [
    {
      "object": "sale",
      "id": "j9cncjq0",
      "status": "Completed",
      "customer": {
        "object": "customer",
        "id": "uj56cbj3943sq1sg",
        "email": "iron.man@email.com",
        "firstname": "Iron",
        "lastname": "Man"
      },
      "payments": {
        "object": "list",
        "total_count": 1,
        "data": [
          {
            "object": "payment",
            "id": "pzrgb2l1lc8w7dp5",
            "sale_id": "j9cncjq0",
            "status": "COMPLETED",
          }
        ]
      }
    },
    {
      "object": "sale",
      "id": "sl8hcw26",
      "status": "Completed",
      "customer": {
        "object": "customer",
        "id": "upwvs7xqbc6zhwxh",
        "email": "the.widows@email.com",
        "firstname": "The",
        "lastname": "Widows"
      },
      "payments": {
        "object": "list",
        "total_count": 1,
        "data": [
          {
            "object": "payment",
            "id": "pjd79f1yygqrm43q",
            "sale_id": "sl8hcw26",
            "status": "COMPLETED",
          }
        ]
      }
    }
  ]
}

=== My Component ===
export class JsonComponent implements OnInit {

saleJSON: Object;

constructor(private _http: JsonService) { }

ngOnInit() {
this._http.getSale().subscribe(data => {
this.saleJSON = data;
console.log(this.saleJSON);
})
}

} 

=== My Service ===
export class JsonService {

api_key = 'API_KEY';

private _urlSale: string = 'https://someting-website/sales?apiKey='+this.api_key;

constructor(private http: HttpClient) { }

getSale() {
return this.http.get(this._urlSale)
}
}

Thanks and Regards,






Replied on September 02, 2019
Got through the below link. This may help you.



Write Answer











©2024 concretepage.com | Privacy Policy | Contact Us