title: Design pattern to optimize ngAfterViewChecked
body: <p>I am trying to get the DOM elements of an angular component through a querySelectorAll method, like this:</p>
  <pre><code>const widgetHTMLElements: NodeListOf&lt;ChildNode&gt; = document.querySelectorAll('medium-editor')[0].childNodes[0].childNodes
  </code></pre>
  <p>My first instinct was to put it in the ngAfterViewInit method, but I was soon to realize the DOM was not ready yet, I know so because I've displayed some console.log(s) and I got the following:</p>
  <p><a href="https://i.stack.imgur.com/1H1Uk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1H1Uk.png" alt="enter image description here" /></a></p>
  <p>What's interesting here is that the NodeList returned has a length <strong>zero</strong> yet contains some elements, I thought at first it's a mere Chrome console inconsistency, but once I've tried to loop over the object, I'd notice it's not working, so I wonder what's up with angular with that regard...</p>
  <p>Anyways, I though it might have to do lifecycle-hooks and went for the <em>ngAfterViewChecked</em>, the good news is that it works fine, I can loop through the returned NodeList and console.log shows something more interesting:</p>
  <p><a href="https://i.stack.imgur.com/Zjn4O.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Zjn4O.png" alt="enter image description here" /></a></p>
  <p>Clearly there's an iteration where the old state of DOM is prevalent, then the first change lets the querySelectorAll return the desired objects.</p>
  <p>The thing is ngAfterViewChecked will execute indefinitely, so I thought I might establish some boolean flag which sets to true once the length of querySelectorAll changes or something; I just don't want to ngAfterViewChecked to continue eating resources while the page is mostly idle, but I don't want to miss significant changes either.</p>
  <p>My question is about whether there exists some Design pattern to limit performance issues with ngAfterViewChecked, if so, what does it look like?</p>