feat(forms): add hasError and getError to AbstractControlDirective (#11985)

Allows cleaner expressions in template-driven forms.

Before:

    <label>Username</label><input name="username" ngModel required #username="ngModel">
    <div *ngIf="username.dirty && username.control.hasError('required')">Username is required</div>

After:

    <label>Username</label><input name="username" ngModel required #username="ngModel">
    <div *ngIf="username.dirty && username.hasError('required')">Username is required</div>

Fixes #7255
This commit is contained in:
Cédric Exbrayat
2016-10-19 18:49:02 +02:00
committed by Alex Rickabaugh
parent 24facdea2d
commit 592f40aa9c
3 changed files with 75 additions and 1 deletions

View File

@ -84,6 +84,8 @@ export declare abstract class AbstractControlDirective {
valid: boolean;
value: any;
valueChanges: Observable<any>;
getError(errorCode: string, path?: string[]): any;
hasError(errorCode: string, path?: string[]): boolean;
reset(value?: any): void;
}