Imagine you have an Angular project and you want to animate a clicked element with jQuery. The element has a position: relative
. You decide to pass the direction of the animation using a parameter variable as shown in this example:
onClickFoo(event :MouseEvent, dir :string) :void {
let targetId :string = (event.currentTarget as Element).id;
$("#" + targetId).animate({
dir: "20px"
});
}
The issue here is that the code ends up assigning a dir=20
attribute to the HTML element instead of interpreting it as a variable. It seems like the compiler is treating 'dir' as a string rather than a variable.
This problem might be caused by the combination of jQuery and TypeScript. If you need to use variables to determine the animation direction, what could be going wrong in this scenario?
Is there a way to make the compiler recognize dir
as a variable, rather than just plain text?