本文整理汇总了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 });
}
}