title: In Angular, how can I run a small script on each component that gets loaded? (diagnostic purposes)
body: <p>I want to run certain diagnostic lines of Javascript as I develop that will console log the <code>alt</code> attribute on all <code>&lt;img&gt;</code> tags in the HTML, for instance.  This is purely for testing and will not go to production of course.  On a single component I would normally run this within the <code>ngAfterContentInit()</code> and/or <code>ngOnChanges()</code> lifecycle hooks, so it would run this script whenever the images in the HTML have been loaded and rendered.</p>
  <p>The JS would just be something simple like <code>getElementsByTagName('img')[0].getAttribute('alt')</code>, but how can I run this each time a component is displayed, so I can check these kinds of things without adding an import to each individual component?  Is there something I can do in the AppModule for instance that controls the components that are loaded?  I would like to run these kinds of scripts on dynamically/lazily loaded components too, if that is possible.</p>