Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angularjs module dependencies

I've defined my main module as such:

angular.module('domiciliations', ['domiciliations.service', 'loggerService', 'person.directives']).
  config(['$routeProvider', function ($routeProvider) {
  $routeProvider.
      when('/domiciliations/mandats', { templateUrl: 'domiciliations/views/mandats.html', controller: mandatsCtrl }).
      when('/domiciliations/mandats/:rum', { templateUrl: 'domiciliations/views/mandat.html', controller: mandatCtrl }).
      otherwise({ redirectTo: '/domiciliations/mandats' });
  }]).
  value('toastr', window.toastr).
  value('breeze', window.breeze);

My problem is how to how specify module dependencies in my controller?

If I do:

angular.module('domiciliations.service', ['ngResource', 'breeze', 'loggerService']).
  factory('Domiciliation', function ($resource, breeze, logger) {
}

Then I get an error 'no module: breeze'.

It works if I do:

angular.module('domiciliations.service', ['ngResource']).
   factory('Domiciliation', function ($resource, breeze, logger) {
}

So how am I suppose to specify dependencies on breeze and logger?

like image 466
Sam Avatar asked Apr 16 '13 07:04

Sam


1 Answers

breeze is not a module - it's a value (shorthand for service) in the domiciliations module: value('breeze', window.breeze);.

When you do:

angular.module('domiciliations.service', ['ngResource', 'breeze', 'loggerService']).
  factory('Domiciliation', function ($resource, breeze, logger) {
}

You configure the domiciliations.service module with dependencies to the modules ngResource, breeze and loggerService. Angular can't find the breeze module and throws an exception.

Assuming loggerService is a module and logger is a service in this module, the following should work (breeze and logger will get injected in the factory function):

angular.module('domiciliations.service', ['ngResource','loggerService']).
   factory('Domiciliation', ['$resource','breeze','logger',
     function ($resource, breeze, logger) {
    }
  ])
like image 127
joakimbl Avatar answered Oct 21 '22 20:10

joakimbl