how do i add angular-moment filter here?

时间:2015-11-21 08:52:48

标签: angularjs angular-moment

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

2 个答案:

答案 0 :(得分:1)

你还没有包括' angularMoment'在你的模块中作为依赖。  如下所示:

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)

并确保您已在index.html中包含angular-moment.js文件

我希望这会有所帮助。如果有任何疑问,请告诉我

答案 1 :(得分:0)

您不需要添加任何指令来在项目中使用momentjs,就像在SPA主页中的任何其他脚本一样引用它,并在任何控制器上使用它。

通过指令加载它的唯一好处是将它声明为依赖,并且可以将其模拟为测试,如果你不关心它,只需像没有Angular一样使用它。