"Fossies" - the Fresh Open Source Software Archive

Member "angular-1.7.9/docs/partials/api/ng/function/angular.injector.html" (26 Nov 2019, 3959 Bytes) of package /linux/www/angular-1.7.9.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) HTML source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 <a href='https://github.com/angular/angular.js/edit/v1.7.x/src/auto/injector.js?message=docs(angular.injector)%3A%20describe%20your%20change...#L3' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit">&nbsp;</i>Improve this Doc</a>
    2 
    3 
    4 
    5 <a href='https://github.com/angular/angular.js/tree/v1.7.9/src/auto/injector.js#L3' class='view-source pull-right btn btn-primary'>
    6   <i class="glyphicon glyphicon-zoom-in">&nbsp;</i>View Source
    7 </a>
    8 
    9 
   10 <header class="api-profile-header">
   11   <h1 class="api-profile-header-heading">angular.injector</h1>
   12   <ol class="api-profile-header-structure naked-list step-list">
   13     
   14     <li>
   15       - function in module <a href="api/ng">ng</a>
   16     </li>
   17   </ol>
   18 </header>
   19 
   20 
   21 
   22 
   23 
   24 <div class="api-profile-description">
   25   <h2 id="overview">Overview</h2>
   26   <p>Creates an injector object that can be used for retrieving services as well as for
   27 dependency injection (see <a href="guide/di">dependency injection</a>).</p>
   28 
   29 </div>
   30 
   31 
   32 
   33 
   34 <div>
   35   
   36 
   37   
   38 
   39   <h2 id="usage">Usage</h2>
   40     
   41       <p><code>angular.injector(modules, [strictDi]);</code></p>
   42 
   43 
   44     
   45 
   46     
   47 <section class="api-section">
   48   <h3 id="angular.injector-arguments">Arguments</h3>
   49 
   50 <table class="variables-matrix input-arguments">
   51   <thead>
   52     <tr>
   53       <th>Param</th>
   54       <th>Type</th>
   55       <th>Details</th>
   56     </tr>
   57   </thead>
   58   <tbody>
   59     
   60     <tr>
   61       <td>
   62         modules
   63         
   64         
   65       </td>
   66       <td>
   67         <a href="" class="label type-hint type-hint-array">Array.&lt;string|Function&gt;</a>
   68       </td>
   69       <td>
   70         <p>A list of module functions or their aliases. See
   71     <a href="api/ng/function/angular.module"><code>angular.module</code></a>. The <code>ng</code> module must be explicitly added.</p>
   72 
   73         
   74       </td>
   75     </tr>
   76     
   77     <tr>
   78       <td>
   79         strictDi
   80         
   81         <div><em>(optional)</em></div>
   82       </td>
   83       <td>
   84         <a href="" class="label type-hint type-hint-boolean">boolean</a>
   85       </td>
   86       <td>
   87         <p>Whether the injector should be in strict mode, which
   88     disallows argument name annotation inference.</p>
   89 
   90         <p><em>(default: false)</em></p>
   91       </td>
   92     </tr>
   93     
   94   </tbody>
   95 </table>
   96 
   97 </section>
   98     
   99 
  100     <h3 id="angular.injector-returns">Returns</h3>
  101 <table class="variables-matrix return-arguments">
  102   <tr>
  103     <td><a href="" class="label type-hint type-hint-injector">injector</a></td>
  104     <td><p>Injector object. See <a href="api/auto/service/$injector">$injector</a>.</p>
  105 </td>
  106   </tr>
  107 </table>
  108 
  109   
  110   
  111   
  112 
  113 
  114 
  115   
  116   <h2 id="examples">Example</h2><p>Typical usage</p>
  117 <pre><code class="lang-js">// create an injector
  118 var $injector = angular.injector([&#39;ng&#39;]);
  119 
  120 // use the injector to kick off your application
  121 // use the type inference to auto inject arguments, or use implicit injection
  122 $injector.invoke(function($rootScope, $compile, $document) {
  123   $compile($document)($rootScope);
  124   $rootScope.$digest();
  125 });
  126 </code></pre>
  127 <p>Sometimes you want to get access to the injector of a currently running AngularJS app
  128 from outside AngularJS. Perhaps, you want to inject and compile some markup after the
  129 application has been bootstrapped. You can do this using the extra <code>injector()</code> added
  130 to JQuery/jqLite elements. See <a href="api/ng/function/angular.element"><code>angular.element</code></a>.</p>
  131 <p><em>This is fairly rare but could be the case if a third party library is injecting the
  132 markup.</em></p>
  133 <p>In the following example a new block of HTML containing a <code>ng-controller</code>
  134 directive is added to the end of the document body by JQuery. We then compile and link
  135 it into the current AngularJS scope.</p>
  136 <pre><code class="lang-js">var $div = $(&#39;&lt;div ng-controller=&quot;MyCtrl&quot;&gt;{{content.label}}&lt;/div&gt;&#39;);
  137 $(document.body).append($div);
  138 
  139 angular.element(document).injector().invoke(function($compile) {
  140   var scope = angular.element($div).scope();
  141   $compile($div)(scope);
  142 });
  143 </code></pre>
  144 
  145 </div>
  146 
  147