<h1><code ng:non-bindable="">$injector</code>
<span class="hint">(service in module <code ng:non-bindable="">AUTO</code>
)</span>
</h1>
<div><h2 id="Description">Description</h2>
<div class="description"><p><code>$injector</code> is used to retrieve object instances as defined by
<a href="api/angular.module.AUTO.$provide"><code>provider</code></a>, instantiate types, invoke methods,
and load modules.</p>

<p>The following always holds true:</p>

<pre class="prettyprint linenums">
  var $injector = angular.injector();
  expect($injector.get('$injector')).toBe($injector);
  expect($injector.invoke(function($injector){
    return $injector;
  }).toBe($injector);
</pre>

<h3>Injection Function Annotation</h3>

<p>JavaScript does not have annotations, and annotations are needed for dependency injection. The
following ways are all valid way of annotating function with injection arguments and are equivalent.</p>

<pre class="prettyprint linenums">
  // inferred (only works if code not minified/obfuscated)
  $inject.invoke(function(serviceA){});

  // annotated
  function explicit(serviceA) {};
  explicit.$inject = ['serviceA'];
  $inject.invoke(explicit);

  // inline
  $inject.invoke(['serviceA', function(serviceA){}]);
</pre>

<h4>Inference</h4>

<p>In JavaScript calling <code>toString()</code> on a function returns the function definition. The definition can then be
parsed and the function arguments can be extracted. <em>NOTE:</em> This does not work with minfication, and obfuscation
tools since these tools change the argument names.</p>

<h4><code>$inject</code> Annotation</h4>

<p>By adding a <code>$inject</code> property onto a function the injection parameters can be specified.</p>

<h4>Inline</h4>

<p>As an array of injection names, where the last item in the array is the function to call.</p></div>
<div class="member method"><h2 id="Methods">Methods</h2>
<ul class="methods"><li><h3 id="get">get(name)</h3>
<div class="get"><p>Return an instance of the service.</p><h4 id="Parameters">Parameters</h4>
<ul class="parameters"><li><code ng:non-bindable="">name – {string} – </code>
<p>The name of the instance to retrieve.</p></li>
</ul>
</div>
</li>
<li><h3 id="instantiate">instantiate(Type, locals)</h3>
<div class="instantiate"><p>Create a new instance of JS type. The method takes a constructor function invokes the new operator and supplies
all of the arguments to the constructor function as specified by the constructor annotation.</p><h4 id="Parameters">Parameters</h4>
<ul class="parameters"><li><code ng:non-bindable="">Type – {function} – </code>
<p>Annotated constructor function.</p></li>
<li><code ng:non-bindable="">locals<i>(optional)</i> – {Object=} – </code>
<p>Optional object. If preset then any argument names are read from this object first, before
the <code>$injector</code> is consulted.</p></li>
</ul>
</div>
</li>
<li><h3 id="invoke">invoke(fn, self, locals)</h3>
<div class="invoke"><p>Invoke the method and supply the method arguments from the <code>$injector</code>.</p><h4 id="Parameters">Parameters</h4>
<ul class="parameters"><li><code ng:non-bindable="">fn – {!function} – </code>
<p>The function to invoke. The function arguments come form the function annotation.</p></li>
<li><code ng:non-bindable="">self<i>(optional)</i> – {Object=} – </code>
<p>The <code>this</code> for the invoked method.</p></li>
<li><code ng:non-bindable="">locals<i>(optional)</i> – {Object=} – </code>
<p>Optional object. If preset then any argument names are read from this object first, before
the <code>$injector</code> is consulted.</p></li>
</ul>
</div>
</li>
</ul>
</div>
</div>
