Skip to content

Instantly share code, notes, and snippets.

@asleepwalker
Created October 13, 2015 13:04
Show Gist options
  • Save asleepwalker/0eb3fa4033ab98cbb416 to your computer and use it in GitHub Desktop.
Save asleepwalker/0eb3fa4033ab98cbb416 to your computer and use it in GitHub Desktop.
ng-empty | ng-filled
app.config(function($provide) {
$provide.decorator('ngModelDirective', function($delegate) {
var last = $delegate[0].controller.length - 1,
controller = $delegate[0].controller[last],
EMPTY_CLASS = 'ng-empty',
NON_EMPTY_CLASS = 'ng-filled';
$delegate[0].controller[last] = function($scope, $exceptionHandler, $attrs, $element, $parse, $animate) {
controller.apply(this, arguments);
var context = this,
toggle = function (value) {
if (context.$isEmpty(value)) {
$animate.removeClass($element, NON_EMPTY_CLASS);
$animate.addClass($element, EMPTY_CLASS);
} else {
$animate.removeClass($element, EMPTY_CLASS);
$animate.addClass($element, NON_EMPTY_CLASS);
}
return value;
};
this.$formatters.push(toggle);
this.$parsers.push(toggle);
};
return $delegate;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment