在Angular控制器中使用moment-duration-format插件

Ale*_*exG 5 javascript angularjs momentjs

我正在尝试使用moment-duration-format插件格式化MomentJS持续时间。我将如何在Angular控制器中使用此插件?似乎一旦导入JS,它就应该开箱即用,但事实并非如此。

我已经在index.html中导入了momentJS和MDF JS文件:

// MomentJS
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.min.js"></script>
// moment-duration-format plugin
<script src="bower_components/moment-duration-format/lib/moment-duration-format.js"></script>
Run Code Online (Sandbox Code Playgroud)

但是,当我在控制器中调用以下行时,出现错误:

console.log( moment.duration(123, "minutes").format("h:mm") );
Run Code Online (Sandbox Code Playgroud)

错误:

TypeError: moment.duration(...).format is not a function...
Run Code Online (Sandbox Code Playgroud)

Cát*_*tos 0

在您的应用程序中包含您的 lib 文件,例如在文件部分中添加的路由文件中,然后您只需要像这样调用它

console.log("时刻 -> ", 时刻());