I am currently in a TS component doing validations, however I have an event in a javascript file that I called as follows:
ngOnInit(): void {
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.src = 'assets/js/ruleta.js';
head.appendChild(script);
}
This is my roulette.js script
var indicator = new TimelineMax();
var spinWheel = new TimelineMax();
indicator.to(active, .13, { rotation: -10, transformOrigin: "65% 36%", ease: Power1.easeOut })
.to(active, .13, { rotation: 3, ease: Power4.easeOut })
.add("end");
// Luckywheel animation
spinWheel.to(wheel, 5, {
rotation: deg, transformOrigin: "50% 50%", ease: Power4.easeOut, onUpdate: (
function () {
//_gsTransform: current position of the wheel
tolerance = currentRotation - lastRotation;
if (Math.round(currentRotation) % (360 / 12) <= tolerance) {
if (indicator.progress() > .2 || indicator.progress() === 0) {
indicator.play(0);
}
}
}
)
});
spinWheel.add("end");
Basically I am trying to call an animation that spins a roulette wheel, the thing is that I would like to call the Javascript function from Typescript, so that the animation is executed
girarRueda(){
activarRuleta(360);
}
Something similar. Is there any way to call such a function from TS?
ADD:
i tried this
girarRueda2(){
this.script.activarRuleta();
}
Because I previously declared a script.src in the ngOnInit, but still no results
Assuming we have the following Javascript roulette.js :
You can use it from TypeScript like this:
It should work perfectly, cheers.
I managed to solve it like this:
To define a function that is in my Javascript file, in Typescript, using the same name I placed:
Then you import the javascript with the AppenChield:
And therefore, you will be able to use the function anywhere in the TS file, simply by calling it: