AngularJS:在每个表单字段中添加ng-form是不是很糟糕?

时间:2015-07-04 22:56:02

标签: angularjs

我正在考虑在每个表单字段中添加一个ng-form,以便我可以使用css而不是ng-show来显示/隐藏字段错误(以减少观察者)。我需要注意哪些严重的缺点?

例如我想转换以下内容:

j

对此:

(HTML)

<div id="fld_field1" class="form-group">
    <label for="field1" class="control-label col-xs-6">Field 1</label>
    <div class="control-wrapper col-xs-6">
        <input  class="form-control"  ng-required="true" name="field1"  type="text" ng-model="fm.data.field1" id="field1"/>
        <small class="hints">
            <div class="error" ng-show="fm.field1.$error.required && fm.field1.$dirty">Field is required.</div>
            <div class="error" ng-show="!fm.field1.$valid && !fm.field1.$error.required && fm.field1.$dirty">Field is invalid.</div>
        </small>
    </div>
</div>

(CSS)

<div ng-form id="fld_field1" class="form-group">
    <label for="field1" class="control-label col-xs-6">Field 1</label>
    <div class="control-wrapper col-xs-6">
        <input  class="form-control"  ng-required="true" name="field1"  type="text" ng-model="fm.data.field1" id="field1"/>
        <small class="hints">
            <div class="error error-required">Field is required.</div>
            <div class="error error-invalid">Field is invalid.</div>
        </small>
    </div>
</div>

0 个答案:

没有答案