本文整理匯總了TypeScript中@angular/forms.AbstractControl.markAsDirty方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript AbstractControl.markAsDirty方法的具體用法?TypeScript AbstractControl.markAsDirty怎麽用?TypeScript AbstractControl.markAsDirty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@angular/forms.AbstractControl
的用法示例。
在下文中一共展示了AbstractControl.markAsDirty方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: 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]);
}
}
}
}
}
示例2: setValue
/**
* Changes the value of a control
*/
setValue(control: AbstractControl | string, value: any, markAsDirty?: boolean): AbstractControl {
control = this.getControl(control);
if (markAsDirty) {
control.markAsDirty();
}
control.setValue(value);
return control;
}
示例3: beforeEach
beforeEach(() => {
form = new FormGroup({
x: new FormControl(
'',
null,
CdValidators.unique((value) => {
return observableOf('xyz' === value);
})
)
});
x = form.get('x');
x.markAsDirty();
});
示例4: dirty
/*
Ensures a programmatic change to an AbstractControl value is marked as dirty (and by default as touched)
prior to the change, properly invoking validation and the display of any validation errors.
*/
changeControlValue( control: AbstractControl, value: any, markTouched: boolean = true ) : void {
control.markAsDirty();
control.markAsTouched( markTouched );
control.setValue( value );
}