Answer the question
In order to leave comments, you need to log in
Angular. How to validate input in child component?
Good day!
There is such a problem. It is necessary to validate the form, but the problem is that the inputs are placed in separate components in which the logic necessary for business is hidden. How to validate inputs in child components?
Patent.html
<form [formGroup]="form" (ngSubmit)="submit()">
<input type="text" name="one" formControlName="one"><br><br>
<app-childten formControlName="two"></app-childten>
<button>Send</button>
</form>
form: FormGroup
ngOnInit() {
this.form = new FormGroup({
one: new FormControl('', [Validators.required]),
two: new FormControl('', [Validators.required]),
})
}
submit() {
console.log(this.form)
}
<input type="text" name="two" formControlName="two">
Answer the question
In order to leave comments, you need to log in
1. https://medium.com/@a.yurich.zuev/angular-nested-t...
2. or explicitly pass `form` to children
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question