I've come to Angular from a Grails background where you would define your business rules validation in one place against a domain model. GORM.... So when I've come to Angular, by way of Ionic, I'm surprised to not see something familiar. Am I missing something here? Is there a better way?
You can implement validation in any case you want. Just add 1 more layer between angular forms and your domain. In general, Angular doesn't dictate what way your application should work. It just gives you instruments for interacting with browser and APIs.
You always can implement Domain#valid()
method and update fields via Reactive Forms.
@Component({})
export class MyComponent implements OnInit{
public form: Form = this.fb.group({
fName: ['', []],
lName: ['', []]
});
constructor(fb: FormBuilder){}
ngOnInit(){
this.form.valueChanges.subscribe((form) => {
let entity: Entity = new Entity(form);
let errors: ValidationErrors = entity.valid();
if(errors.length){
this.form.setErrors(errors);
this.form.updateValueAndValidity();
}
});
}
}