Skip to content

Instantly share code, notes, and snippets.

@michaeljymsgutierrez
Created March 20, 2017 04:55
Show Gist options
  • Save michaeljymsgutierrez/b61b7c94e011cad40467298a75822907 to your computer and use it in GitHub Desktop.
Save michaeljymsgutierrez/b61b7c94e011cad40467298a75822907 to your computer and use it in GitHub Desktop.
Update ng-model using custom-directive
.directive('noNegativeValue',function(){
//Custom Directive for checking negative value
return {
restrict: 'A',
require: '?ngModel',
link: function(scope, element , attrs, ngModel){
scope.$watch(attrs.ngModel, function(val){
if(val < 0){
ngModel.$setViewValue('0');
ngModel.$render();
}
});
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment