angularjs - How to add custom data validator directly without specialized directive? -


in short have custom data validator without writing entire directive it.

here case -- have editor component/directive several input fields. let's (this content of template of editor directive):

<input ng-model="phrase"></input> <input ng-model="translation"></input> 

the "classic" approach write:

<input ng-model="translation" validator-1 validator-2 validator-3... ></input> 

and add appropriate directives validators. don't approach, because validators not general purpose, tailored template only, , adding them suggests there kind of composition (that ok change something), , not true -- there atomic entity "input + validators" = "translation".

thus add custom validator directly code of editor directive.

how it?

so far experimenting finding out inside ngmodel of editor directive, since editor directive not have model entire editor, distinct fields (as shown above) failed @ requiring ngmodel editor.


Comments