0

I'm getting an object from getView() metho,d and the object contains a list of name. I want those names to be stored in an array. How can I do this?

getView() {
    return this.http.get(this.viewUrl).map(response => response.json());
}

Component.ts

  constructor(private userService: userservices,  private route: Router){
              this.userService.userView().subscribe(data => {this.userData = data.nameKey, alert(data)},
          err => {
            console.log('Error get values from services in Branch Component');
          });

               alert(this.userData);
               this.itemResource = new DataTableResource(this.userData);

          }

DataTable.html

<data-table id="persons-grid" headerTitle="Employees View"
        [items]="items" [itemCount]="itemCount" (reload)="reloadItems($event)"
        (rowClick)="rowClick($event)"
        (rowDoubleClick)="rowDoubleClick($event)" [rowTooltip]="rowTooltip">

    <data-table-column [property]="'name'" [header]="'Name'"
        [sortable]="true" [resizable]="true"> </data-table-column> <data-table-column
        [property]="'email'" [header]="'Branch Name'" [sortable]="true"
        [resizable]="true"> </data-table-column>

i refered from this link https://www.npmjs.com/package/angular-4-data-table-bootstrap-4

11
  • response.json() contans the name? Commented Feb 6, 2018 at 12:26
  • yes but its come as list of object[object ,object] Commented Feb 6, 2018 at 12:28
  • please add the response format of the endpoint being called Commented Feb 6, 2018 at 12:30
  • @Manik added answer please check it Commented Feb 6, 2018 at 12:32
  • its come as object i checked Commented Feb 6, 2018 at 12:43

1 Answer 1

1

try this.

getView() {
return this.http.get(this.viewUrl).map(response => response.json());        
}
this.getView().subscribe((data) => {
this.arrayValue=data.nameKey;
  alert(JSON.stringify(this.userData));
})
Sign up to request clarification or add additional context in comments.

4 Comments

I guess, This is what OP want
i try that given i got values in alert [{"id=1,"name":"kumar" and etc } ]...@Ajmal sha
so u get the data from this u want to show the name value? then change the alert code to alert(JSON.stringify(this.userData[0].name))
i getting the values in alert but i want to pass array value to DataTableResource pls see above i have update

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.