Search code examples
angularjsangularjs-service

Error injecting custom service into another custom service


Now that I have my script files referenced in my view template, I am having trouble injecting the first one into the second one.

If I unplumb the dependency that LearnerService has on SCORMService, everything displays according to plan, but is of course nonfunctional because LearnerService relies on SCORMService to accomplish its purpose. When I try to actually use my SCORMService within my LearnerService, I get Michael Bay explosions and sad trombones.

So, I'm using ngRoute. That might be important; maybe not. I'll list my app.js, my script ordering in index.html, learnerServices.js, SCORMServices.js, and controllers.js

app.js

'use strict';
var app = angular.module('client', [
   'ngRoute'
  ,'controllers'
  ,'services.proxy.scorm'
  ,'services.proxy.lms'
]);

index.html

...
<script src="js/app.js"></script>
  <script src="js/controllers.js"></script>
  <script src="js/SCORMService.js"></script>
  <script src="js/LearnerServices.js"></script>
</head>
<body>

    <div class="view-container">
        <div ng-view class="view-frame"></div>
    </div>

</body>
</html>

LearnerServices.js

'use strict';
var learnerServices = angular.module('services.proxy.lms',['scorm-service']);

learnerServices.factory('LearnerService', [ 'scorm-service', function(){
    return true;
}]);

SCORMService.js

'use strict';
var services = angular.module('services.proxy.scorm', []);
services.factory('scorm-service',function(){
   var foo = {};
   foo.bar = "snazzy jazzy";
   return foo;

});

I seem to be attempting to corner the market on stupid mistakes today. Can anyone see what stupid mistake I did this time?


Solution

  • This line should be:

    var learnerServices = angular.module('services.proxy.lms',['services.proxy.scorm']);
    

    Notice in your code you are saying the module has a dependency on scorm-service however the dependency for the module is on services.proxy.scorm