Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In the <code>config</code> phase, the services declared are not available yet. Only those who have been declared using <code>provide</code> will through <code>serviceNameProvider</code> (add <code>Provider</code> after the name you have defined). For example:</p> <pre><code>.provide('RouterService', function() { var service = { }; var routes = { "/login": { templateUrl: 'app/modules/login-manager/partials/login.tpl.html', requiredLogin: false }, "/dashboard": { templateUrl: 'app/modules/dashboard-manager/partials/dashboard.tpl.html', controller: 'DashboardController', requiredLogin: true }}; service.getRoutes = function() { return routes; }; this.$get = function() { return service; } this.setupRoute = function(data) { /* something here */ }; }; </code></pre> <p>When you get a provider, all method defined on <code>this</code> will be available. When you access the normal service, what is injected is the return of the <code>$get</code> function. Depending on what you need, you either need to change your service to use <code>provide</code> or ask to be injected with the service in the <code>run</code> method:</p> <pre><code>angular.module('bac', ['bac.route-manager']) .config(function ($routeProvider, RouterServiceProvider) { // Here, only RouterServiceProvider.setupRoute will be available }).run(function (RouterService) { // Here, the service singleton return with the $get function will // be injected console.log(RouterService.getRoutes()); }); </code></pre> <p><strong>Edit</strong></p> <p>As a side note, I believe that even if you have defined your <code>RouterService</code> as a <code>service</code>, asking for <code>RouterServiceProvider</code> would still work but no method will be present as <code>service</code> is essentially a wrapper around <code>provider</code> to only return the function in the <code>$get</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