Created
March 20, 2017 04:55
-
-
Save michaeljymsgutierrez/b61b7c94e011cad40467298a75822907 to your computer and use it in GitHub Desktop.
Update ng-model using custom-directive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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