Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h1>TLDR: In <strong>one line</strong> the command you are looking for:</h1> <pre><code>angular.element(document.body).injector().get('serviceName') </code></pre> <hr> <h3>Deep dive</h3> <p>AngularJS uses <strong>Dependency Injection (DI)</strong> to inject services/factories into your components,directives and other services. So what you need to do to get a service is to get the <strong>injector</strong> of AngularJS first (the injector is responsible for wiring up all the dependencies and providing them to components).</p> <p>To get the <strong>injector</strong> of your app you need to grab it from an element that angular is handling. For example if your app is registered on the body element you call <code>injector = angular.element(document.body).injector()</code></p> <p>From the retrieved <code>injector</code> you can then get whatever service you like with <code>injector.get('ServiceName')</code></p> <p>More information on that in this answer: <a href="https://stackoverflow.com/questions/13400687/cant-retrieve-the-injector-from-angular">Can&#39;t retrieve the injector from angular</a> <br> And even more here: <a href="https://stackoverflow.com/questions/10490570/call-angular-js-from-legacy-code">Call AngularJS from legacy code</a></p> <hr> <p>Another useful trick to get the <code>$scope</code> of a particular element. Select the element with the <strong>DOM inspection tool</strong> of your developer tools and then run the following line (<code>$0</code> is always the selected element): <br> <code>angular.element($0).scope()</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload