new to JS and will delete if not allowed. I have got some regular JS code which I have been working with trying to switch this into a controller.
For the given example what would be the most optimised way. I have seen cases with directives, counters and so on however I am thinking this is very complicated for what I am doing. I have so far manage to bind seconds and tens to screen however I am having issues with the $interval for updating, do I require .watch, .promises .then? (sorry for newb question any help would be great)
JS Script
window.onload = function() {
var seconds = 00;
var tens = 00;
var appendTens = document.getElementById("tens");
var appendSeconds = document.getElementById("seconds");
var buttonStart = document.getElementById('button-start');
var buttonStop = document.getElementById('button-stop');
var buttonReset = document.getElementById('button-reset');
var Interval;
buttonStart.onclick = function () {
clearInterval(Interval);
Interval = setInterval(startTimer, 10);
};
buttonStop.onclick = function () {
clearInterval(Interval);
};
buttonReset.onclick = function () {
clearInterval(Interval);
tens = "00";
seconds = "00";
appendTens.innerHTML = tens;
appendSeconds.innerHTML = seconds;
console.log("clear()");
};
function startTimer() {
tens++;
if (tens < 9) {
appendTens.innerHTML = "0" + tens;
}
if (tens > 9) {
appendTens.innerHTML = tens;
}
if (tens > 99) {
console.log("seconds");
seconds++;
appendSeconds.innerHTML = "0" + seconds;
tens = 0;
appendTens.innerHTML = "0" + 0;
}
if (seconds > 9) {
appendSeconds.innerHTML = seconds;
}
}
};
This is how I am binding HTML to the screen
<span id="seconds">{{ seconds+":"+tens }}</span>