简体   繁体   English

如何从angular 1.5组件获取表单验证

[英]how to get form validation from angular 1.5 component

I know how to set form validation from angular 1.5 我知道如何从angular 1.5设置表单验证

for example: $scope.voiceForm.$setValidity 例如: $scope.voiceForm.$setValidity

but how can i get the form-validaiton status from the component code? 但是如何从组件代码中get form-validaiton状态?

couldn't find in the documentation 文档中找不到

Good afternoon, 下午好,

Use this reference: Link 使用此参考: 链接

    <form name="demoForm">
      <input name="amount" type="number" ng-model="amount" max="100">
      <div ng-messages="demoForm.amount.$error">
        <div ng-message="number">Should be a number</div>
        <div ng-message="max">The number is too large.</div>
      </div>
    </form>
    {{demoForm.amount.$valid}}

If you take the code and tests by adding it outside the "form" {{demoForm.amount.$valid}} will give you the status of the form at all times. 如果您接受代码并通过将其添加到“表单”之外进行测试,{{demoForm.amount。$ valid}}将始终为您提供表单的状态。

By default a correct number will be set to "true" but if you put a number such as 12020929292 that is too long, it will skip the error and {{demoForm.amount.$valid}} will go from true to false immediately. 默认情况下,正确的数字将设置为“ true”,但是如果您输入的数字如12020929292太长,它将跳过该错误,并且{{demoForm.amount。$ valid}}将立即从true变为false。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM