我在一个字段上进行了验证:
<div class="col-lg-6">
STRADA
<input name="street" #street="ngModel" class="form-control" [(ngModel)]="model.Address.Street" required/>
<div *ngIf="street.errors && (street.dirty || street.touched)" class="alert alert-danger">
<div [hidden]="!street.errors.required">
Strada este obligatorie!
</div>
</div>
</div>
如何在打字稿方面访问street.errors
?
提前致谢。
答案 0 :(得分:2)
您可以使用@ViewChild
访问Element import { ....., ViewChild } from '@angular/core';
export class YourComponent.... {
@ViewChild('street') streetElement;
private checkElementStatus(): void {
console.log(this.streetElement.errors)
}
}