Being a developer who shifting to angular js from asp.net mvc, I am disappointed with the default validation implementation of angular js validation. It seems that angular, by default implement the client-side validation in the view and this violate the rules of separation of concern (imho).
Personally, I am more fond to implementing the validation rules in the viewmodel instead of view. Not sure whether this is widely adopted and recommended in angular js community.
So my question is:
1) Is the default implementation of validation in angular js a preferred way than separating it into view model??
2) Is there any existing angular library that implement the validation logic in separate layer?
I am expecting something like this.
model.User = {
Name: { validate: required, errorMessage: 'Name is required'},
Price: {
validate: number, errorMessage: 'Price should be number',
validate: number.min = 0, number.max = 100, errorMessage = 'Price should be between 0 and 100',
}
}
<input ng-model="User.Name" name="Name">
<input ng-model="User.Price" name="Price>