本文整理匯總了TypeScript中@angular/forms.AbstractControl類的典型用法代碼示例。如果您正苦於以下問題:TypeScript AbstractControl類的具體用法?TypeScript AbstractControl怎麽用?TypeScript AbstractControl使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了AbstractControl類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: setValue
const setPgNum = (pgs): AbstractControl => {
setValue('poolType', 'erasure');
const control = setValue('pgNum', pgs);
fixture.detectChanges();
fixture.debugElement.query(By.css('#pgNum')).nativeElement.dispatchEvent(new Event('blur'));
return control;
};
示例2: 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;
}
}
示例3: 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]);
}
}
}
}
}
示例4: dateRangeValidator
export function dateRangeValidator(c: AbstractControl): {[key: string]: any} {
// Get controls in group
const startDateC = c.get('startDate');
const startTimeC = c.get('startTime');
const endDateC = c.get('endDate');
const endTimeC = c.get('endTime');
// Object to return if date is invalid
const invalidObj = { 'dateRange': true };
// If start and end dates are valid, can check range (with prefilled times)
// Final check happens when all dates/times are valid
if (startDateC.valid && endDateC.valid) {
const checkStartTime = startTimeC.invalid ? '12:00 AM' : startTimeC.value;
const checkEndTime = endTimeC.invalid ? '11:59 PM' : endTimeC.value;
const startDatetime = stringsToDate(startDateC.value, checkStartTime);
const endDatetime = stringsToDate(endDateC.value, checkEndTime);
if (endDatetime >= startDatetime) {
return null;
} else {
return invalidObj;
}
}
return null;
}
示例5:
export const passwordMatcher = (control: AbstractControl): {[key: string]: boolean} => {
const password = control.get('password');
const confirm = control.get('confirm');
if (!password || !confirm) {
return null;
}
return password.value === confirm.value ? null : { nomatch: true };
};
示例6: it
it('validates name', () => {
hasError(form.get('name'), 'required');
isValid(setValue('name', 'some-name'));
component.info.pool_names.push('someExistingPoolName');
hasError(setValue('name', 'someExistingPoolName'), 'uniqueName');
hasError(setValue('name', 'wrong format with spaces'), 'pattern');
});
示例7: it
it('validates pgNum in creation mode', () => {
formHelper.expectError(form.get('pgNum'), 'required');
formHelper.setValue('poolType', 'erasure');
formHelper.expectValid(setPgNum(-28));
expect(form.getValue('pgNum')).toBe(1);
formHelper.expectValid(setPgNum(15));
expect(form.getValue('pgNum')).toBe(16);
});
示例8: handleInvalidTimeEvent
handleInvalidTimeEvent(data: string) {
if (this.control) {
this.control.setValue('');
this.model.setInvalidTime();
this.model.clientValid = false;
this.control.setErrors({ [this.model.getMessage()]: true });
}
}