0

Am new to angularjs and given a codebase to add angular-moment (moments.js) to a module.

The module is defined is as follows:

angular.module("xyz", ["ngRoute",
                              "ui.bootstrap",
                              "infinite-scroll",
                              "uiGmapgoogle-maps",
                              "googlechart"],          
     function($interpolateProvider) {
        $interpolateProvider.startSymbol("[[");
        $interpolateProvider.endSymbol("]]");
})
    .factory("principal", principal)
    .factory("authorization", authorization)
    .factory("pingService", abc)

When i add angularMoment just after "googlechart" i get a "unpr" angular error. I did include both moments.js and angular-moments.js in my html.

I need to use javascript moments lib in my angular code.

Please help.

thanks

BoCode
  • 847
  • 4
  • 17
  • 33

2 Answers2

1

You haven't included 'angularMoment' in your module as dependency. Do like following :

angular.module("xyz", ["ngRoute",
                              "ui.bootstrap",
                              "infinite-scroll",
                              "uiGmapgoogle-maps",
                              "googlechart","angularMoment"],          
     function($interpolateProvider) {
        $interpolateProvider.startSymbol("[[");
        $interpolateProvider.endSymbol("]]");
})
    .factory("principal", principal)
    .factory("authorization", authorization)
    .factory("pingService", abc)

And make sure , you have included the angular-moment.js file in your index.html

I hope this helps. Do let me know in case of any query

Vaibhav Pachauri
  • 2,671
  • 2
  • 19
  • 32
0

You don't need to add any directive to use momentjs in your project, reference it just like any other script in your SPA main page an use it on any controler.

The only benefit of loading it via a directive is having it declared as a dependence, and the possibility of mocking it for tests, if you don't care about this, just use it as you would do without Angular.

Vi100
  • 4,080
  • 1
  • 27
  • 42