title: How to check for the existence of a module without an error being raised?
body: <p>In Angular 1.2, <code>ngRoute</code> is a separate module so you can use other community routers like <code>ui.router</code> instead.</p>
  
  <p>I'm writing an open-source module that aims to work for multiple different router implementations. So how can I check which router is loaded or exists?</p>
  
  <p>I'm doing the following inside a factory in my module, but it does not work the way I expect it to:</p>
  
  <pre><code>if (angular.module("ngRoute"))
    // Do ngRoute-specific stuff.
  else if (angular.module("ui.router"))
    // Do ui.router-specific stuff.
  </code></pre>
  
  <p>It raises an error for whichever module is not loaded. For example, if the app is using <code>ui.router</code>, then the following error is raised for the <code>ngRoute</code> check:</p>
  
  <blockquote>
    <p>Uncaught Error: [$injector:nomod] Module 'ngRoute' is not available!
    You either misspelled the module name or forgot to load it. If
    registering a module ensure that you specify the dependencies as the
    second argument.</p>
  </blockquote>