I would like to call function from setInterval(). Here is the idea:
class Greeter {
element: HTMLElement;
span: HTMLElement;
timerToken: number;
constructor(element: HTMLElement) {
this.element = element;
this.element.innerHTML += "The time is: ";
this.span = document.createElement('span');
this.element.appendChild(this.span);
this.span.innerText = new Date().toUTCString();
//this.element.style.cssText = "-webkit-transform:rotate(7deg)";
//this.element.style.transition = "-webkit-transform: rotate(180deg)";
}
start() {
this.timerToken = setInterval(this.runningLoop(this.element), 500);
}
stop() {
clearTimeout(this.timerToken);
}
runningLoop(element: HTMLElement) {
this.element.style.cssText = "-webkit-transform:rotate(7deg)";
}
}
window.onload = () => {
var el = document.getElementById('content');
var greeter = new Greeter(el);
greeter.start();
};
In this case i getting an exception:
Unhandled exception at line 13, column 9. Microsoft JScript runtime error: Invalid argument.
So i tried as following :
this.timerToken = setInterval(function () { this.runningLoop(this.element) }.bind, 500);
No exception but nothing happens..
Any ideas ?