Having trouble returning a string to another method in an Ionic TypeScript file. Our goal is to return JSON.stringify(res) and assign it to the stringset variable. We initially tried testing by simply returning the string "hi", but even that did not work. We have attempted returning various types like any or string, but the IDE seems to disapprove of using the string type.
We need assistance figuring out how to successfully return a string from the postCall method so that it can be stored in the stringset variable.
navNextQuestion() {
let stringset = this.postCall("A004");
this.navCtrl.push('QuestionPage', {
firstPassed: stringset,
secondPassed: "it did pass"
});
}
//Below passes variable to PHP file#
public postCall(id:string): string {
let data=JSON.stringify({answer_id:id, type:"answer"});
this.http.post('http://localhost/retrieve-data.php',data)
.map(res => res.json())
.subscribe(res => {
alert("success "+JSON.stringify(res));
//parses JSON response into array (uncomment below when ready)
//this.response = JSON.stringify(res);
return "hi";