Skip to content Skip to sidebar Skip to footer

Angularjs Formatter - How To Display Blank Instead Of Zero

Please see this previous question: Format input value in Angularjs The issue I am having is that (as is the case in the fiddle in the answer to the question above, i.e. http://jsfi

Solution 1:

you can simply put an if-else condition to your directive and it is done...

        ctrl.$parsers.unshift(function (viewValue) {
            console.log(viewValue);
            if(viewValue){
                var plainNumber = viewValue.replace(/[^\d|\-+|\.+]/g, '');
                elem.val($filter('number')(plainNumber));
                return plainNumber;
            }else{
                return'';
            }
        });

here is working JSFIDDLE

Post a Comment for "Angularjs Formatter - How To Display Blank Instead Of Zero"