Search code examples
javascriptangularjsangular-materialng-messages

Error message has been always showing. How to handle this error?


Once I fill the data in this field it needs to go off. But it didn't.

<md-input-container class="md-block" flex-gt-sm>
   <label>Budget</label>
   <input name="budget" ng-model="newTrip.budget" required>
   <div ng-messages="newForm.budget.$error" ng-show="newForm.budget.$touched" role="alert">
       <div ng-message="required">
           <span>Number is required</span>
       </div>
   </div>
</md-input-container>

enter image description here


Solution

  • Try changing it slightly:

    <div ng-messages="newForm.budget.$error"
      ng-if="newForm.budget.$invalid && newForm.budget.$touched"
      ...>
    </div>
    

    I shortened it slightly, but try adding in the ng-if and see if it shows/hides your error.