本文整理匯總了TypeScript中@angular/forms.AbstractControl.setErrors方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript AbstractControl.setErrors方法的具體用法?TypeScript AbstractControl.setErrors怎麽用?TypeScript AbstractControl.setErrors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@angular/forms.AbstractControl
的用法示例。
在下文中一共展示了AbstractControl.setErrors方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: addError
static addError(control: AbstractControl, errorId: string, value: any) {
if (!control.errors) {
control.setErrors({ [errorId]: value });
} else if (!control.hasError(errorId)) {
control.errors[errorId] = value;
}
}
示例2: setErrors
protected setErrors(control: AbstractControl, errors: FormErrors): void {
if (isPresent(errors.errors)) {
let controlErrors = {};
errors.errors.forEach((error) => {
controlErrors[error] = true;
});
control.setErrors(controlErrors);
control.markAsDirty({
onlySelf: true
});
}
if (isPresent(errors.children)) {
for (let name in errors.children) {
if (errors.children.hasOwnProperty(name)) {
let child = control.get(name);
if (null !== child) {
this.setErrors(child, errors.children[name]);
}
}
}
}
}
示例3: handleInvalidTimeEvent
handleInvalidTimeEvent(data: string) {
if (this.control) {
this.control.setValue('');
this.model.setInvalidTime();
this.model.clientValid = false;
this.control.setErrors({ [this.model.getMessage()]: true });
}
}
示例4: removeError
static removeError(control: AbstractControl, errorId: string) {
if (control.errors && control.hasError(errorId)) {
if (Object.keys(control.errors).length > 1) {
delete control.errors[errorId];
} else {
control.setErrors(null);
}
}
}
示例5: return
return (control:AbstractControl) => {
if (control.dirty) {
control.setErrors({CheckingDuplicatedItem: true});
clearTimeout(currentTimeout);
return new Promise((resolve) => {
currentTimeout = setTimeout(() => {
apartmentService.getApartments().subscribe((apartments:Apartment[]) => {
if (apartments.some((apartment:Apartment) => (apartment.name!=itemName && apartment[fieldname].toLowerCase()==control.value.toLowerCase()))) {
resolve({DuplicatedItem: true})
} else {
resolve(null);
}
});
}
, 1000);
})
} else {
control.setErrors(null);
return new Promise(null);
}
}