title: Accessing an Angular service that may or may not exist
body: <p>I'm working on an Angular project at the minute that is designed to very modular - <a href="https://stackoverflow.com/a/37675548/5436257">sections of the app can be enabled and disabled for different clients using Webpack.</a> This structure is working nicely for me so far, but one issue I've run into is working out how to handle services that might not always be present.</p>
  
  <p>My current solution is pretty simple - I use <code>$injector.has()</code> to check if the service currently exists, and if so, I use <code>$injector.get()</code> to grab it:</p>
  
  <pre><code>function initialize($injector) {
      if ($injector.has("barcode")) {
          let barcode = $injector.get("barcode");
  
          // Do stuff with the barcode service
      }
  }
  </code></pre>
  
  <p>This seems to work - however, I can't find much information on the use of this pattern and whether or not it has any potential downsides.</p>
  
  <p>So, my questions are:</p>
  
  <ul>
  <li>Are there any caveats to using the injector this way that I should be aware of?</li>
  <li>Is there a better/more idiomatic way of doing this?</li>
  </ul>