Skip to content

Instantly share code, notes, and snippets.

@codethug
Forked from tommck/knockoutExtensions.js
Last active October 2, 2016 16:12
Show Gist options
  • Save codethug/6423433 to your computer and use it in GitHub Desktop.
Save codethug/6423433 to your computer and use it in GitHub Desktop.
/*
* read-only date display with momentjs
* use like this: data-bind="moment: dateVar, format: 'YYYY-MM-DD'"
* The "format" is optional and will default to "MM/DD/YYYY"
*/
ko.bindingHandlers.moment = {
update: function (element, valueAccessor, allBindingsAccessor, viewModel) {
var val = valueAccessor();
var date = moment(ko.utils.unwrapObservable(val));
var format = allBindingsAccessor().format || 'MM/DD/YYYY';
element.innerText = date.format(format);
}
};
@jpolvora
Copy link

thanks, solved my problem with knockout js and systemjs modules. I just changed the default format to 'L'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment