I have a directive which replaces a select element with a custom input control. Here's a simplified version of it:
angular.module('MyModule', []).directive('reflector', function($timeout) {
return {
require: 'ngModel',
link: function(scope, element, attrs, ngModel) {
element.insertAfter('<input type=text id="new-' + attrs.id + '" />');
element.hide()
}
};
});
I'd like this custom input control to reflect the valid/invalid state of the original select element, i.e. add the ng-invalid class when the base element is invalid.
Is there any way to watch for changes to ngModel.$invalid? I know I can do scope.$watch(attrs.ngModel, ...), but that gives me the model data, not the form element's valid/invalid state..