Skip to content

Instantly share code, notes, and snippets.

@mcnilz
Created February 4, 2016 11:43
Show Gist options
  • Save mcnilz/09f2169a19c32e7009a2 to your computer and use it in GitHub Desktop.
Save mcnilz/09f2169a19c32e7009a2 to your computer and use it in GitHub Desktop.
angular.module("app")
.directive('formError', function () {
return {
restrict: 'A',
require: '^form',
scope: {
formError: '=formError'
},
link: function (scope, element, attrs, form) {
scope.form = form;
scope.$watchGroup([
'form.' + scope.formError + '.$invalid',
'form.' + scope.formError + '.$dirty',
'form.$submitted'
], function (watch) {
element.toggleClass('has-error', watch[0] && (watch[1] || watch[2]));
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment