What's the best way to reduce repetition of form element attributes in angularjs? -
i'm designing angularjs 1.5.x app have lots of forms , lots of fields per form. i'm finding i'm repeating attributes lot, e.g.:
<div class="form-group"> <label class="control-label" for="thing.field1">field 1</label> <input class="form-control ctrl-md" type="text" id="thing.field1" name="field1" ng-model="thing.field1" ng-maxlength="30" required uib-tooltip="field 1 required" tooltip-placement="right" tooltip-trigger="none" tooltip-is-open="thingform1.field1.$invalid && showvalidationerr('thing1')" ng-blur="fieldblur('thing1')"> </div>
i've attempted use directive + template, , works more or less, seems complex , slow.
is there way make input
reusable? or should used doing lot of copy+paste in editor?
in addition reducing repetitive coding, nice able change elements in 1 place, in case want change tooltip position on fields example.
there many ways. have @ library http://angular-formly.com/. in projects use plain inputs , writing directives in complex cases, 2 field controls. or special field card expiration date.
update
ok, have @ pls. angular: better form validation solution
you have 3 solutions:
- to store attributes is.
- to store group of attributes, commonly used together, in directive. or use directive utilize array of properties. validation directive in example.
- to use directive transclusion utilize 1st , 2nd approach. can swap elements position (such label, input control, error hint) in single place. plus can create property like...
preset
on directive , store attribute presets in it.
so, told, there many ways reduce number of attribute repetition.
Comments
Post a Comment