AngularJS Built-in directives ngRequired


Example

The ng-required adds or removes the required validation attribute on an element, which in turn will enable and disable the require validation key for the input.

It is used to optionally define if an input element is required to have a non-empty value. The directive is helpful when designing validation on complex HTML forms.

HTML

<input type="checkbox" ng-model="someBooleanValue">
<input type="text" ng-model="username" ng-required="someBooleanValue">