当前错误消息显示在文本框下方。但我想在标签和文本框下面的整行中显示它
我通过移动下面的 div 进行了尝试,但它不起作用。我看到的 cssinvalid-feedback
仍然是display: none
. 它应该更改为display: block
或删除
<div class="form-group">
<div class="row">
<div class="col-sm">
<label>First Name</label>
</div>
<div class="col-sm">
<input type="text" formControlName="firstName" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.firstName.errors }" />
</div>
</div>
<div class="row">
<div *ngIf="submitted && f.firstName.errors" class="invalid-feedback">
<div *ngIf="f.firstName.errors.required">First Name is required</div>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm">
<label>First Name</label>
</div>
<div class="col-sm">
<input type="text" formControlName="firstName" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.firstName.errors }" />
</div>
</div>
<div class="row">
<div *ngIf="submitted && f.firstName.errors" class="invalid-feedback">
<div *ngIf="f.firstName.errors.required">First Name is required</div>
</div>
</div>
</div>
如果我像上面那样更改代码,我不会收到错误消息,但我仍然会得到文本框的边框红色。
期望:错误消息应该如下图所示
https://stackblitz.com/edit/angular-7-reactive-form-validation-jhuxvm