我正在尝试,
<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
不起作用,但 Indidual components validation works on blur on blur of input
但是,如果我将 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: Cannot read property 'onlinePaymentId' of undefined/p>
帮助我了解如何使单独验证和最终表单验证一起工作。Angular Ver 1.5,现在无法升级。需要 1.5 的解决方案。
最佳答案
Form name
属性应该有 sadadPaymentForm
而不是 vm.sadadPaymentForm
。由于您没有正确指定表单 name
,因此验证失败。
name="vm.sadadPaymentForm"
应该是
name="sadadPaymentForm"
关于javascript - ng-form模板中的 Angular 丢失范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53517337/