I really hope someone can help me out with this one cause I can’t figure out what is wrong with my logic.
In my TS file I have a simple function like this to generate eventid
public eventid: number;
createEventId(){
$.get("http://localhost:8000/getEvents.php", (data)=>{
var obj1 = jQuery.parseJSON(data);
for (var i = 0; i < obj1.length; i++){
var eventid = parseInt(obj1[i].event_id);
if (eventid < 1){
eventid = 1;
} else {
eventid = eventid + 1;
}
}
return eventid;
});
}
I tried logging out eventid when it was returned and got a value of 5 (int), which was expected.
However, when I tried to use that value in the next function as following, it gave me undefined value.
eventname: string;
eventdate = new Date().toISOString();
createEvent(){
this.createEventId();
var eventname = this.eventname;
var eventdate = this.eventdate;
console.log(eventname);
console.log(eventdate);
console.log(this.eventid);
}
I have declared eventid as a public variable so it should be accessible from anywhere right? Please tell me what I’m missing. Thank you all.