angular removes ng-model variable if ng-required is true

Issue

as in the title.. how to prevent such operations to happen? Here is a link to the official site, see the example. The variable user.name is bound to the first input userName and if the input is empty the object user.name is removed. How can I disable this functionality of angularjs?

Solution

Try ng-model-options="{allowInvalid: true}" to update the model even for invalid entries.

<input ng-model="user.name" required ng-model-options="{allowInvalid: true}">

Answered By – Vinay K

Answer Checked By – Marie Seifert (AngularFixing Admin)

Leave a Reply

Your email address will not be published.