What is the difference between required and ng-required?

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

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

3条回答
  •  余生分开走
    2020-11-28 19:45

    I would like to make a addon for tiago's answer:

    Suppose you're hiding element using ng-show and adding a required attribute on the same:

    will throw an error something like :

    An invalid form control with name='' is not focusable

    This is because you just cannot impose required validation on hidden elements. Using ng-required makes it easier to conditionally apply required validation which is just awesome!!

提交回复
热议问题