My website is displaying two words one letter at a time, with a 0.1s delay between letters and a 3s pause after each full word. I attempted using setTimeout
, but it's not functioning as expected. What could be the issue in my code?
var app = angular.module("app", []);
app.controller('mainCtrl', function ($scope) {
var values = ['.com', 'available'];
var index = 0;
$scope.comval = '';
function changeText (){
if(values[index].length == $scope.comval.length) {
$scope.comval = '';
index++;
if (index >= values.length) {
index = 0;
}
}
else
{
$scope.comval = values[index].substring(0, $scope.comval.length+1);
$scope.$apply();
console.log($scope.comval);
}
}
setInterval(changeText,100);
});
You can see this effect on another site by visiting this link. Look for the section shown in the image below:
https://i.sstatic.net/SPwGU.png
Check out the code snippet on JSFiddle.