I want to implement the reactive form validations in angular 2.When user clicks on submit button the page will scroll up to the required error.
@ViewChild('focuserror') errorElement: ElementRef;
ngAfterViewInit() {
this.renderer.invokeElementMethod(this.errorElement.nativeElement.querySelector('.ng-invalid'), 'focus');
}
Is this the right code? It's throwing error
you can do this:
formSubmitFunction() {
const firstElementWithError = document.querySelector('.ng-invalid');
if (firstElementWithError) {
firstElementWithError.scrollIntoView({ behavior: 'smooth' });
}
}
you can use any class you have used in form validation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With