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