I searched all over stackoverflow and found alot of posts, so im pretty sure its duplicate, however i could not find any post that was noob friendly and clear to me, maybe because im pretty new to typescript.
What i am currently working with is typescript classes, and click in Jquery. Normaly this or $(this) works for getting the Jquery item, but then againin TS this is normally reserved for the class:
When i use Jquery the this becomes replaced by the Jquery object.
So i am currently working with:
HTML:
<a data-id="6" class="js-set-crime-option btn btn-primary">Kies</a>
TS:
class Dealers
{
constructor() {
$(".js-set-crime-option").click(this.set);
}
public set() {
var a = $(this);
alert(a.data("id"));
debugger;
// i want to call test here
}
public test(id: string) {
alert("helooooooo" + id);
}
}
how can i call test in this scope?
EDIT: i found this not sure if it is the correct solution though
var me: Dealers;
class Dealers
{
name:string = "friend";
constructor() {
$(".js-set-crime-option").click(this.set);
me = this;
}
public set() {
var a = $(this);
me.test(a.data("id"));
}
public test(id: string) {
alert("helooooooo" + id + this.name);
}
}