urish / angular-moment

Moment.JS directives for Angular.JS (timeago and more)
MIT License
2.6k stars 397 forks source link

Accessing moment() in your javascript #236

Closed lykyd closed 7 years ago

lykyd commented 8 years ago

Can you give a code example of how to "inject the moment variable into the constructor." ?

hamzamihaidanielx commented 8 years ago

Anyone please?

lucasgranberg commented 8 years ago

Im not shure I understand the question .

The moment object is provided as an angular constant here. I think it is also a global variable but it is cleaner to access it trough angulars dependency injection system.

angular.module('fooApp')
  .controller('FooCtrl', function ($scope,outlet,moment) {
    console.log(moment().hour(8).minute(0).second(0).toDate());
  });