title: How to access DOM element in AngularJS
body: <p>I'm new to AngularJS. I have an app with basic routing etc but I'd like to add a script that will add some interactivity to my home screen. This is a typewriter js script:</p>
  
  <pre><code>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);
  })();
  </code></pre>
  
  <p>This works locally but when I deploy to Heroku it says:</p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot set property 'innerHTML' of null</p>
  </blockquote>
  
  <p>This tells me that the script executes before the homepage view is loaded. What's the best solution for this. Can I stick this code inside app.js and if so, how do I do that?</p>
  
  <p>I have already tried to wrap my code inside window.onload and it didn't make any difference.</p>