Skip to content

Instantly share code, notes, and snippets.

@mbenford
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbenford/ad12fc449796a156694a to your computer and use it in GitHub Desktop.
Save mbenford/ad12fc449796a156694a to your computer and use it in GitHub Desktop.
Simple Angular directive to force data to be bound even when it's deemed invalid by some validator
app.directive('forceDatabinding', function() {
return {
require: 'ngModel',
link: function(scope, element, attrs, ngModel) {
ngModel.$parsers.push(function(value) {
return value || ngModel.$viewValue;
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment