我正在尝试这个

    <div ng-form="sadadPaymentForm" class="sadadPaymentForm"  ng-if="vm.isSadadEnabled" name="sadadPaymentForm"  validate-popup-form>
     <div ng-if="vm.isSadadEnabled">
       <div class="credit-debit-card-div" ng-include="'sadadTemplate'" ng-show="vm.view_tab == 'tab7'">
       </div>
    </div>
   </div>
   <span ng-show="vm.view_tab=='tab7' && vm.isSadadEnabled">
     <button type="button" class="primary inline pay-now" id="paynowbtn" ng-disabled="!vm.checked3 || vm.sadadPaymentForm.$invalid" ng-click="vm.payByVoucher();" analytics-on="click" analytics-event="uaevent" analytics-eventcategory="Payment" analytics-eventaction="PayNow"
             analytics-eventlabel="Pay now">
               Pay by sadad
     </button>
   </span>


而且,我的模板位于另一个html文件中

  <script type="text/ng-template" id="sadadTemplate">
    <input fieldlabel="Online Payment ID" type="text" name="onlinePaymentId" ng-model="vm.sadadpayment.onlinePaymentId"  class="form-control input-type-text"
                    ng-model-options="{ debounce: 100 }" validationKey-required="PaymentAdress1IsRequired" required maxlength="200">
  </script>


在这里vm.sadadPaymentForm.$invalid不起作用,但是独立组件验证在输入模糊时对模糊有效。

但是,如果我将vm添加到ng-form,即像这样


    <div ng-form="vm.sadadPaymentForm" class="sadadPaymentForm"  ng-if="vm.isSadadEnabled" name="vm.sadadPaymentForm"  validate-popup-form>
     <div ng-if="vm.isSadadEnabled">
       <div class="credit-debit-card-div" ng-include="'sadadTemplate'" ng-show="vm.view_tab == 'tab7'">
       </div>
    </div>
   </div>


在这里vm.sadadPaymentForm.$invalid可以工作,但是对输入的模糊(例如TypeError),单个组件验证失败:无法读取未定义的属性'onlinePaymentId'

帮助我了解如何使个人验证和最终表单验证一起工作。AngularVer 1.5,现在无法升级。需要使用1.5的解决方案。

最佳答案

表格name属性应具有sadadPaymentForm,尽管vm.sadadPaymentForm。由于您没有正确指定name表格,因此验证失败。

name="vm.sadadPaymentForm"


应该

name="sadadPaymentForm"

09-16 07:59