What is the difference between required and ng-required?

前端 未结 3 1549
天涯浪人
天涯浪人 2020-11-28 19:26

What is the difference between required and ng-required (form validation)?

3条回答
  •  星月不相逢
    2020-11-28 19:45

    AngularJS form elements look for the required attribute to perform validation functions. ng-required allows you to set the required attribute depending on a boolean test (for instance, only require field B - say, a student number - if the field A has a certain value - if you selected "student" as a choice)

    As an example, and are essentially the same thing

    If you are wondering why this is this way, (and not just make or ), it is due to the limitations of HTML - the required attribute has no associated value - its mere presence means (as per HTML standards) that the element is required - so angular needs a way to set/unset required value (required="false" would be invalid HTML)

提交回复
热议问题