Why my global varibale do not override after post request

Viewed 45

I just need that me test object equill new data, but after override it in async function but it still old adter whenGET request

var fcrForm = {
 employees:[]
};
$httpBackend.whenGET('http://localhost:3001/forms').respond(200, fcrForm);
$httpBackend.whenPUT('http://localhost:3001/forms').respond(function (method, url, data) {

    fcrForm = JSON.parse(data)
    return [200, fcrForm, {}]
});
2 Answers

You can fix this using promise.then

const lol = async()=> {
const data = await fetch('https://jsonplaceholder.typicode.com/todos/1')
const res = await data.json()
test = res;
  return res;
}

lol().then(function(res) {
  console.log("test: " + test);
});
Related