title: Optional dependencies in AngularJS
body: <p>I'm trying to implement a controller in AngularJS which is used across multiple pages. It makes use of some services. Some of them are loaded on all pages, some - not. I mean it is defined in different files, and these files are loaded independently. But if I do not load these services on all pages I got error:</p>
  
  <pre><code>Error: Unknown provider: firstOtionalServiceProvider &lt;- firstOtionalService
  </code></pre>
  
  <p>So, I need to load scripts on all pages. Can I declare dependency as optional in Angular? E.g:</p>
  
  <pre><code>myApp.controller('MyController', ['$scope', 'firstRequiredService', 'secondRequiredService', 'optional:firstOptionalService', 'optional:secondOptionalService', function($scope, firstRequiredService, secondRequiredService, firstOptionalService, secondOptionalSerivce){
  
      // No need to check, as firstRequiredService must not be null
      firstRequiredService.alwaysDefined();
  
      // If the dependency is not resolved i want Angular to set null as argument and check
      if (firstOptionalService) {
          firstOptionalService.mayBeUndefinedSoCheckNull();
      }
  
  }]);
  </code></pre>