Last active
August 22, 2018 05:51
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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