AngularJS: list all form errors

前端 未结 4 733
执念已碎
执念已碎 2021-01-29 23:45

Background: I am currently working on an application with tabs; and I\'d like to list the fields / sections that fail validation, to direct the user to look for errors in the r

4条回答
  •  执念已碎
    2021-01-30 00:09

    As @c0bra pointed out in the comments the form.$error object is populated, it just doesn't like being dumped out as JSON.

    Looping through form.$errors and it's nested objects will get the desired result however.

    • {{ key }} errors
      • {{ e.$name }} has an error: {{ key }}.

    All the credit goes to c0bra on this.

    Another option is to use one of the solutions from this question to assign unique names to the dynamically created inputs.

提交回复
热议问题