我有一个打字脚本:
dataxForm: fromGroup
this.dataxForm = new FormGroup({
'Description':new FormControl(null, Validaros.required};
'Name':new FormControl(null, Validators.required})
我有一个html:
<mat-divider></mat-divider>
<form [formGroup]="dataxForm">
<ng-template #editDescription>
<input formControlName = "Description item">
<textarea matInput cdsTextareaAutosize [formControl]="controls.description"></textarea>
<small class="text-danger" *ngIf=dataxForm.get('Description').invalid || dataxForm.get('Description').touched"> Description is a required field></small>
<mat-divider></mat-divider>
<form [formGroup]="dataxForm">
<ng-template #editDescription>
<input formControlName = "Name">
<textarea matInput cdsTextareaAutosize [formControl]="controls.description"></textarea>
<small class="text-danger" *ngIf=dataxForm.get('Name').invalid || dataxForm.get('Name').touched"> Name is a required field></small>
<button mat-button [disabled] = "dataxForm.invalid (click)="submitForm">Submit Form</button>
加载页面后,验证错误消息立即正确显示;输入下盒子;1( 如何一旦验证要求,就删除输入下的错误消息清除?2( 如何在所有验证时解冻提交按钮是否清除了要求?
dataxForm.get('Description'(和dataxForm.get('Name'(在呈现组件时无效。
试试这个:
<small class="text-danger" *ngIf="(dataxForm.get('Description').touched || dataxForm.get('Description').dirty) && dataxForm.get('Description').invalid"> Description is a required field></small>