Just starting to get the hang of Typescript, coming from a JavaScript background. Ran into an issue and need some help troubleshooting.
document.querySelector("#sr").addEventListener("click", function () {
console.log(1);
new GetApi().entered_name();
});
The event listener works fine initially, but not consistently afterwards. Oddly enough, removing new GetApi().entered_name()
fixes the problem entirely.
Below is the function causing the trouble:
entered_name()
{
console.log(document.getElementById("fname").value);
return fetch("https://localhost:5001/api?search="+document.getElementById("fname").value)
.then(Response=>Response.json())
.then(data=>{
console.log(data[0]);
let res =new UserData(data[0]);
console.log(res);
let obj = new Display1();
obj.showUserData(res);
}).catch(err=>console.log(err));
}
And here is the problematic showUserData()
:
export class Display1
{
showUserData(obj : UserData){
{
document.body.innerHTML += "Props in HTML tags";
}
}
}