Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 字段在我开始键入之前变为红色_Angular_Typescript_Angular5 - Fatal编程技术网

Angular 字段在我开始键入之前变为红色

Angular 字段在我开始键入之前变为红色,angular,typescript,angular5,Angular,Typescript,Angular5,问题是,在我开始键入之前,字段是经过验证的。当我打开包含屏幕截图中所有字段的页面时,字段已经是红色的。 我发布了一些html代码片段和类型脚本代码,因为所有字段看起来都一样。 我将非常感谢你的帮助 primaryFormGroup=新FormGroup{}; primaryFirstName=newFormControl,[Validators.required]; ngAfterViewInit:void{ this.primaryFormGroup.addControl'primaryFi

问题是,在我开始键入之前,字段是经过验证的。当我打开包含屏幕截图中所有字段的页面时,字段已经是红色的。 我发布了一些html代码片段和类型脚本代码,因为所有字段看起来都一样。 我将非常感谢你的帮助

primaryFormGroup=新FormGroup{}; primaryFirstName=newFormControl,[Validators.required]; ngAfterViewInit:void{ this.primaryFormGroup.addControl'primaryFirstName',this.primaryFirstName; this.formGroupPersonalInfo.addControl'primaryFormGroup',this.primaryFormGroup; } Html {{primaryFirstName.value?.length | | 0}}/12 名字段是必需的。 {{primaryFirstName.value?.length | | 0}}/12
在显示错误之前,还应检查是否触摸了它

<mat-error *ngIf="primaryFirstName.hasError('required') && primaryFirstName.touched">

当您使用formControl时,为什么要使用[ngModel]?为了确保不会发生这种情况,请将您的*ngIf更改为:!primaryFirstName.pristine&&primaryFirstName.hasError'required'隐藏错误消息,但字段仍以红色突出显示。好啊你不需要在[ngModel]中使用formcontrol,我已经修复了它,但对你没有好处。谢谢