我正在尝试对angular 6 mat-dialog进行验证,以便在单击mat-dialog选项时获取错误消息 . 如果项目没有在mat-dialog选项中,则会生成验证 . 如何实现这一目标?我尝试了很多,但没有得到输出 . 帮助我 .
我的代码如下
getError() {
this.stringData='Please provide a valid carrier id';
return this.stringData;}filter(val: any): any[] {
console.log(this.editFormData.controls['carrierID'].value);
let valid;
this.prepaidCarrierTripId.map(x => {
if (x.trpCarrierId.startsWith(this.editFormData.controls['carrierID'].value)) {
valid = true;
}
})
if (!valid) {
this.getError();
}
else
this.error = null;
return this.prepaidCarrierTripId.filter(option =>
option.trpCarrierId.toLowerCase().includes(val.toLowerCase()));}
我的HTML
<input matInput type="text" name="carrierID" (click)="load()" formControlName="carrierID"
placeholder="{{ 'Carrier ID'}}" maxlength="6" [matAutocomplete]="auto">
<mat-error class="error-msg" [value]="getError()">{{getError()}}</mat-error>
<mat-error class="error-msg">CarrierId is required</mat-error>
<mat-autocomplete autoActiveFirstOption #auto="matAutocomplete" (optionSelected)="selected($event)">
<mat-option *ngFor="let option of filteredOptions | async" [value]="option.trpCarrierId">{{option.trpCarrierId}}</mat-option>
</mat-autocomplete>
</mat-form-field>
1 回答