Replace comma with a dot in input field
angularjs
Solution
I think there is no need to do this like a directive.
say your template is
<input ng-model='someModel'>
in your controller,
$scope.$watch('someModel',function(newVal){
$scope.someModel = newVal.replace(/,/g,'.');
})
ng-model is a two-way binding, so it should work
Problem
European countries uses a comma-sign (,) instead of a dot (.) when they enter decimal numbers. So I want to replace the dot sign with a comma when users enter input. I'm aware that input=number do this but I need support for IE. I guess directive is the best to do this? I gave it a try with the code below. But it fails. ``` .directive('replaceComma', function(){ return { restrict: 'A', replace: true, link: function(scope, element, attrs){ scope.$watch(attrs.ngModel, function (v) { var convert = String(v).replace(",","."); attrs.NgModel = convert; }); } } }); ``` The convert variable is correct. But the value does not change in the input box. So I guess attrs.ngModel = convert, is wrong?