Home > Mobile >  Angular get data from http put [closed]
Angular get data from http put [closed]

Time:09-17

I'm tring to retrive data from an endpoint something like to put in some datatable: -http://XXXXXX:8080/groups/get

-HTTP PUT

The response should be something like this:

[
 {"GroupId":"0002A",
  "description": "description test one", 
  "Name": "Test02", 
  "department": "dep02"}
 ,
 {"GroupId":"0001A",
  "description": "description test one", 
  "Name": "Test01", 
  "department": "dep01"}
   ,....]

DTO:

export interface DynamicGroup {
 dynamicGroupId: string;
 description: string;
 displayName: string;
 corp: string;
}

service.ts:

  getDynamicGroup() {
     return this.httpClient.put<DynamicGroup[]>('http://XXXXXX:8080/groups/get', null);
  }

component.ts:

 searchGroups() {
  this.userService.getDynamicGroup().subscribe(groups => {
  this.groups =groups. ???  <--- the groups should return the data from message above;
});
}

At this point , I believe that the problem is how I'm calling the endpoint on service.ts , but I'm new on angular and I don't know how to solve this issue to get the data from endpoint.

CodePudding user response:

you should pass the data in getDynamicGroup instead of passing null

EG:

getDynamicGroup(data:DynamicGroup) {
     return this.httpClient.put<DynamicGroup>('http://XXXXXX:8080/groups/get', data);
  }

CodePudding user response:

Solved. The URL from backend was different from the one that was used on frontend.

  • Related