I'm a newcomer to AngularJS and I have successfully set up basic routing in my app. However, I am now looking to enhance the interactivity of my home screen by incorporating a typewriter js script:
const texts = ['123', '456', '789'];
let count = 0;
let index = 0;
let currentText = '';
let letter = '';
(function type() {
if (count === texts.length) {
count = 0;
}
currentText = texts[count];
letter = currentText.slice(0, ++index);
document.querySelector(".typing").innerHTML = letter;
angular.element(document.querySelector('.typing'));
if (letter.length === currentText.length) {
count++;
index = 0;
}
setTimeout(type, 400);
})();
Although this script functions properly on my local environment, it throws an error when deployed to Heroku:
Uncaught TypeError: Cannot set property 'innerHTML' of null
This error suggests that the script is running before the homepage view is fully loaded. What would be the best approach to resolve this issue? Can I integrate this code within app.js, and if so, how would I go about doing that?
I have attempted to enclose my code within window.onload, but it has not made any difference in resolving the error.