I have a JavaScript code in my TypeScript file. It retrieves the attribute from a span element when it is clicked. I want to store this attribute's value in a TypeScript variable and then call a TypeScript function.
Take a look at my ngOnInit method, all I need is to assign the value of link_id
to this.actionid
and then invoke the callpagedata()
function.
Here is the JavaScript code inside my home.ts
:
actionid;
ngOnInit(){
var mainDiv = document.getElementById("mainDiv");
mainDiv.addEventListener("click", function (event) {
console.log("Inside Event Listener");
event.preventDefault();
var link_id = $(event.target).attr("action");
console.log("Actionid is:: " + link_id);
});
}
All I want is to have the value of link_id
stored in this.actionid
and then be able to call the callpagedata()
function. I attempted using this.actionid = linkId
but encountered issues with accessing actionid
within the event listener and link_id
outside of it.
callpagedata(){
}
The HTML code found in home.html is as follows:
<div id="mainDiv">
<span action="10004">Quick Task</span>
<span action="10006">Quick Patrol</span>
</div>