本文整理汇总了TypeScript中@angular/forms.AbstractControl.markAsTouched方法的典型用法代码示例。如果您正苦于以下问题:TypeScript AbstractControl.markAsTouched方法的具体用法?TypeScript AbstractControl.markAsTouched怎么用?TypeScript AbstractControl.markAsTouched使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/forms.AbstractControl
的用法示例。
在下文中一共展示了AbstractControl.markAsTouched方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: buildForm
private buildForm(): void {
this.form = this.formBuilder.group({
firstName: [this.firstName, Validators.required],
lastName: [this.lastName, Validators.required],
email: [this.email, Validators.compose([Validators.required, CustomValidators.email])]
});
this.firstNameControl = this.form.controls.firstName;
this.lastNameControl = this.form.controls.lastName;
this.emailControl = this.form.controls.email;
if (this.item) {
this.firstNameControl.markAsTouched();
this.lastNameControl.markAsTouched();
this.emailControl.markAsTouched();
}
}
示例2: showErrors
export function showErrors(control: AbstractControl) {
if ((control as FormGroup | FormArray).controls) {
// tslint:disable-next-line:forin
for (const name in (control as FormGroup | FormArray).controls) {
showErrors((control as FormGroup).controls[name]);
}
}
control.markAsTouched({ onlySelf: true });
control.updateValueAndValidity({ onlySelf: true });
}
示例3: markAsDeeplyTouched
export function markAsDeeplyTouched(control: AbstractControl): void {
// Mark this control as touched
control.markAsTouched();
// Recursively mark any control children as touched
if (control instanceof FormGroup) {
Object.keys(control.controls).forEach(key => {
const c2 = control.get(key);
if (c2) {
markAsDeeplyTouched(c2);
}
});
}
}
示例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 );
}