jsmreese / moment-duration-format

Format function plugin for the Moment Duration object.
MIT License
968 stars 121 forks source link

Using moment-duration-format with Angular #34

Closed alexg313 closed 8 years ago

alexg313 commented 9 years ago

This may be a trivial issue, but it's giving me a hard time... How would I go about using moment-duration-format in my Angular controllers?

I've imported momentJS and MDF JS file in my index.html:

But when I call the below line in a controller, I get an error:

console.log( moment.duration(123, "minutes").format("h:mm") );

Error:

TypeError: moment.duration(...).format is not a function...

paolomaffei commented 9 years ago
<script src="lib/moment/min/moment.min.js"></script>
<script src="lib/angular-momentjs/angular-momentjs.js"></script>
<script src="lib/moment-duration-format/lib/moment-duration-format.js"></script>

importing files in this order (moment first, angular-momentjs second, moment-duration-format third) should do the trick!

jsmreese commented 8 years ago

My dev branch has better support for modules and exports an initializer function that allows you to setup moment-duration-format on any moment instance... could also help in this situation.