soloPositivos-directive.js
912 Bytes
angular.module('focaDirectivas')
.directive('soloPositivo', 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);
}
};
});