I'm learning AngularJS. Currently, I'm trying to load a third-party module in my service. Specifically, I'm trying to load angular-moment. My service is defined like this:
myApp.factory('myService', ['angularMoment', function(angularMoment) {
  return {
    getLocale: function() {
      return angularMoment.locale();
    }
  }
}]);
If I replace return angularMoment.locale() with return 'someLocale'; my code runs. However, as soon as I reference angularMoment, I get errors. I know it has something to do with the fact that I'm not loading the module correctly. However, I do not know what I'm doing wrong. I just see this error when I run my unit tests:
Error: [$injector:unpr] http://errors.angularjs.org/1.2.22/$injector/unpr?p0=angularMomentProvider%20%3C-%20angularMoment%20%3C-myService (line 36) (1)
What am I doing wrong?
Try 'moment' instead of angularMoment in the service/factor injector. This will give you the object from MomentJS
myApp.factory('myService', ['moment', function(moment) {
  return {
    getLocale: function() {
      return moment.locale();
    }
  }
}]);
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With