I am trying to access a value from a service through a function, but it always return a Promise Object and not the value which I am returning. You can check the code below for details.
function testMtd(flag) {
return fetch("apiURL", {
method: "GET",
json: true
})
.then((response) => {
if (response.ok) {
// console.log(response.json());
return response.json();
} else {
alert(
"Server returned " + response.status + " : " + response.statusText
);
}
})
.then((response) => {
console.log(response.flag);
return response.flag;
})
.catch((err) => {
console.log(err);
});
}
console.log("result: ", testMtd("IN"));
The result is always result: Promise {}
were as is should get the Flag URL from return