Skip to content

Instantly share code, notes, and snippets.

@adamrecsko
Last active August 22, 2018 05:51
Show Gist options
  • Save adamrecsko/9559296 to your computer and use it in GitHub Desktop.
Save adamrecsko/9559296 to your computer and use it in GitHub Desktop.
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));
}
};
});
//for example: <span data-bind="money: myobservable, format:'00,000' " ></span>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment