-1

I have this arrow function:

saveNewPermissions = (newGroupPermissions, groupName) => {
    fetch(this.baseUrl + "/addPermission/group/" + groupName, {
        method: 'PUT',
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
            'Access-Control-Allow-Origin': '*',
        },
        body: JSON.stringify({
            permissions: newGroupPermissions
        })
    }).then(response => response.json())
        .then(json => {
            console.log(JSON.stringify(json))
            return json;
        });
}

That function above is on the Service file, and on my component class i want to get the json that the function returns:

 this.Service.save(newList, groupName)

I tried to do this but it didnt work:

 this.uaaService.saveNewPermissions(newList, groupName).then(response=>{
   console.log(response)
 })
jose azevedo
  • 245
  • 2
  • 3
  • 19
  • 1
    Add `return fetch(.. code...)` – random Mar 23 '19 at 17:55
  • 1
    `'Access-Control-Allow-Origin': '*',` is a **response** header, is has no place being on a request. – Quentin Mar 23 '19 at 17:57
  • Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Agney Mar 23 '19 at 18:21

1 Answers1

0

First of, you would want to return the Promise from the arrow function

saveNewPermissions = (newGroupPermissions, groupName) => {
  return fetch(...) // returns a Promise object
}

then if you expect newList to be an array, you want to do:

this.uaaService.saveNewPermissions(newGroupPermissions, groupName).then((newListJSON) => {
  this.Service.save(newListJSON, groupName);
})