How to fetch values from 2 arrays (json array) in angular?

Asked on December 28, 2017
I have following json array





I want to fetch location name (which is in first array) and location path (which is in second array).

Can any one help me out.

Replied on December 28, 2017
Create a method to access JSON data:

url = ".....";

getData(): Observable<any> {
       return this.http.get(this.url).map(res => res.json());

Now fetch location:

       res => {
 let data = res[0];

Replied on December 28, 2017
If you want to access location name and path both, you can do in following way.

   res => {
   let location = res[0];
   let path = res[1];


Replied on December 28, 2017
@Anupam thank you for the reply. I am trying to display the data in ngx-datatable 

My code in component.ts is as follows:

getAllLocations() {
// alert("comming in component ts");
console.log("comming in component ts");
(data => {
// push our inital complete list
this.rows = data;

My code in html is as follows:

<ngx-datatable-column name="LocationName">
<ng-template let-row="row" ngx-datatable-cell-template>
<ngx-datatable-column name="LocationCode">
<ng-template let-row="row" ngx-datatable-cell-template>
<ngx-datatable-column name="Path">
<ng-template let-row="row" ngx-datatable-cell-template>

How do i print data in data table?

Thanks & Regards

Anita Patil

Write Answer

©2023 | Privacy Policy | Contact Us