Improve this Doc View Source ngRequired

From Get docs
< Directive components in ngAngularjs/docs/1.8/api/ng/directive/ngrequired

Improve this Doc View Source ngRequired

  1. directive in module ng


ngRequired adds the required validator to ngModel. It is most often used for input and select controls, but can also be applied to custom controls.

The directive sets the required attribute on the element if the AngularJS expression inside ngRequired evaluates to true. A special directive for setting required is necessary because we cannot use interpolation inside required. See the interpolation guide for more info.

The validator will set the required error key to true if the required attribute is set and calling NgModelController.$isEmpty with the ngModel.$viewValue returns true. For example, the $isEmpty() implementation for input[text] checks the length of the $viewValue. When developing custom controls, $isEmpty() can be overwritten to account for a $viewValue that is not string-based.

Directive Info

  • This directive executes at priority level 0.


  • as attribute:



Param Type Details
ngRequired expression AngularJS expression. If it evaluates to true, it sets the required attribute to the element and adds the required validator.


© 2010–2020 Google, Inc.
Licensed under the Creative Commons Attribution License 3.0.