I have this code:
form [formGroup]="form">
<input formControlName="name">
<span *ngIf="form.controls.name.invalid">1234</span>
<button #myButton></button>
</form>
and Component:
import { Component, Inject, OnInit } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';
import { DOCUMENT } from '@angular/common';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
constructor(
@Inject(DOCUMENT) private document: Document) {
}
form = new FormGroup({
name: new FormControl('', [Validators.required])
});
ngOnInit() {
document.getElementById('myButton').focus();
}
}
I am getting validation error eventhough I am not even setting a focus on that field.
Any idea?
Thanks