Skip to content

Instantly share code, notes, and snippets.

@snios
snios / knockout-numeral
Created August 22, 2018 05:51 — forked from adamrecsko/knockout-numeral
Knockout binding use Numeral.js to format money. It is a requirejs module, the paths of the numeral and the knockout must be defined in the requirejs config.
define(['knockout','numeral'],function(ko,numeral){
ko.bindingHandlers.money = {
update: function (element, valueAccessor,allBindingsAccessor) {
var format = allBindingsAccessor().format || "00,000";
var value = ko.utils.unwrapObservable(valueAccessor());
$(element).text(numeral(value).format(format));
}
};
});