I'm making web application which contains 2 parts:
Front-end made by Angular 2
Back-end made by ASP.NET Core Web API.
In back-end service, when the model submitted to service is invalid, I respond ModelState back to client, for example:
{
"Name": [
"NAME_MAXLENGTH_EXCEEDED",
"NAME_FORMAT_INVALID"
],
"Password": [
"PASSWORD_REQUIRED"
]
}
I've read some tutorials about angular 2 form validation, like this:
https://medium.com/@daviddentoom/angular-2-form-validation-9b26f73fcb81#.10trjfzel
But, that tutorial doesn't meet my expectation, I want to exploit the ModelState respond back from client as the structure defined above.
And my html should be like this:
<li *ngFor="let validationError in validationErrors.Name">
{{validationError}}
</li>
All I want to keep the structure of client model validation is the same as the modelstate in service.
Can anyone help me please ?
Thank you,