soloPositivos-directive.js 915 Bytes
angular.module('focaDirectivas')
    .directive('soloPositivos', function(){
        return {
            require: 'ngModel',
            scope: true,
            link: function(scope, element, attr, ngModel) {
                ngModel.$parsers.push(function (value) {
                    return '' + value;
                });

                if (!ngModel) return;
                    function modificar(texto) {
                        if (texto) {
                            var cambioInput = texto.replace('-', '');

                            if (cambioInput !== texto) {
                                ngModel.$setViewValue(cambioInput);
                                ngModel.$render();
                            }
                            return cambioInput;
                        }
                    }
                    ngModel.$parsers.push(modificar);
                }
        };
    });