Reputation: 553
hi i have a textbox which should reject the entry of a decimal point. when a user enters a "." then the text box should not make that entry in the text box.
will any ng-functions help ? or a seperate directive needs to be written ?
Upvotes: 0
Views: 396
Reputation: 113
angular.module('app', [])
.controller('myCtrl', function($scope) {
$scope.textinput = '';
})
.directive('noPeriod', function() {
return {
require: 'ngModel',
restrict: 'A',
link: function(scope, element, attrs, modelCtrl) {
modelCtrl.$parsers.push(function(inputValue) {
if (inputValue == undefined)
return ''
cleanInputValue = inputValue.replace('.', '');
if (cleanInputValue != inputValue) {
modelCtrl.$setViewValue(cleanInputValue);
modelCtrl.$render();
}
return cleanInputValue;
});
}
}
});
Upvotes: 1