From your snippets it appears that you are adding the controls dynamically, ie. at the moment the form is constructed and bound to the template, the control xyz
does not exist yet. This might be the root cause. If this is the case you might have to run this.reportForm.get('xyz').updateValueAndValidity()
.
The "static" approach (ie. when you declare the control in the construction phase) works fine for me, ie. I am not able to type d
@Component({
selector: 'my-app',
standalone: true,
imports: [CommonModule, FormsModule, ReactiveFormsModule],
template: `
<form [formGroup]="form">
<input type="number" formControlName="xyz">
</form>
`,
})
export class App {
form = new FormGroup({
xyz: new FormControl('', [Validators.pattern('^[0-9]*$')]),
});
}
Don't be surprised though that the input of type number may accept the letter e
(as part of exponential notation).