I'm trying to create a custom directive that set 'required' and 'disabled' attributes to the element (form input). The directive gets this data from the scope object. But clearing of required field doesn't set my form to invalide state. I think it's about form compilation after changing the attribute. I tried to do that but got an infinite loop :( How to compile my form correctly?
Here is plunker
You could just use
ng-disabled
andng-required
, instead of adding the attributes in a directive.Alternatively, you could define a directive template that uses
ng-disabled
andng-required
, and replace the original element with it:Then, use it like this:
I prefer the first approach, because it can respond to changes to
paintData
. But, you have to repeat the property name several times.If you want to try this code, here is an update of your Plunker.
Recompiling the element could work, but in order to avoid the infinite loop you need to first remove the
meta-validate
attribute (which would cause yet more compiling etc):See, also, this short demo.