How to display server errors in Angularjs with ng-messages

后端 未结 4 1878
情话喂你
情话喂你 2021-02-02 10:30

I have have my angular app validating a sign-up form. On submit, the server also validates the data. I\'m outputting error messages in angular using ng-messages.

Here i

4条回答
  •  无人及你
    2021-02-02 10:59

    A simple solution is to have two arrays. One for client side and one for server side errors which is populated in your controller. You can hide the server side errors if client errors exists or opposit to avoid double messages.

    The reason I choose to have two arrays instead of populating the forms array is that the JavaScript controller should not know or be dependent on the structure of the HTML. The HTML AngularJS template should be bound to the controller, not opposit.

    A note on the label: Users using screen-readers will not get your error messages read out loud to them if they are not wrapped inside the label.

提交回复
热议问题