Skip to content

Instantly share code, notes, and snippets.

@astral303
Created December 17, 2013 15:47
Show Gist options
  • Save astral303/8007019 to your computer and use it in GitHub Desktop.
Save astral303/8007019 to your computer and use it in GitHub Desktop.
coerce null to undefined to work around angular.js #5442
'use strict';
angular.module('app')
.directive('coerceNullToUndefined', function () {
return {
restrict: 'A',
require: 'ngModel',
link: function (scope, element, attrs, ngModel) {
ngModel.$formatters.push(function (value) {
if (value === null) {
return undefined;
}
return value;
}
);
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment