Angular (2) Server-side validation (and best practices)

I'm having trouble implementing a simple server-side form validation using angular 2.

given the following scenario:

  • Simple form with fields for login and password. (attached to component view via ngForm / ngModel directives)
  • Template Based Form
  • Using synchronous validation
  • Server response. The JSON object has the following {field: error} ex form , if the login and password are empty, the answer is:{login: 'required', password: 'required'}

As soon as it is sent, I have a response from the server, but I do not know how to update the state of each ngModel associated with the view control to show it in the user interface

This is a very common scenario, and I am surprised that I have many problems finding the right documentation. (customer check is very well explained, on the other hand)

Any help appreciated! Greetings :)

+6
source share
1 answer

I look around the Internet on server-side validation models and I have not found official documentation, but instead I have useful articles - one of them from Stack Over ~ - that may help you a little. I have not tested it yet, still looking for information and maybe you have already found the answer to your problem. Anyway, here is a short list with articles on server-side checks using different APIs:

https://www.carlrippon.com/integrating-validation-in-angular-2-and-asp-net-core/

https://www.puzzle.ch/blog/articles/2017/01/18/server-side-validations-with-angular-2

Angular 2 ()

+1

Source: https://habr.com/ru/post/1016823/


All Articles