|
7 | 7 | */ |
8 | 8 |
|
9 | 9 | import {InjectionToken} from '@angular/core'; |
10 | | -import {NgControl, FormGroupDirective, NgForm} from '@angular/forms'; |
| 10 | +import {FormControl, FormGroupDirective, Form, NgForm} from '@angular/forms'; |
11 | 11 |
|
12 | 12 | /** Injection token that can be used to specify the global error options. */ |
13 | 13 | export const MD_ERROR_GLOBAL_OPTIONS = new InjectionToken<ErrorOptions>('md-error-global-options'); |
14 | 14 |
|
15 | 15 | export type ErrorStateMatcher = |
16 | | - (control: NgControl, parentFormGroup: FormGroupDirective, parentForm: NgForm) => boolean; |
| 16 | + (control: FormControl, form: FormGroupDirective | NgForm) => boolean; |
17 | 17 |
|
18 | 18 | export interface ErrorOptions { |
19 | 19 | errorStateMatcher?: ErrorStateMatcher; |
20 | 20 | } |
21 | 21 |
|
22 | | -export function defaultErrorStateMatcher(control: NgControl, formGroup: FormGroupDirective, |
23 | | - form: NgForm): boolean { |
24 | | - |
25 | | - const isInvalid = control && control.invalid; |
26 | | - const isTouched = control && control.touched; |
27 | | - const isSubmitted = (formGroup && formGroup.submitted) || |
28 | | - (form && form.submitted); |
| 22 | +export function defaultErrorStateMatcher(control: FormControl, form: FormGroupDirective | NgForm) { |
| 23 | + const isInvalid = control.invalid; |
| 24 | + const isTouched = control.touched; |
| 25 | + const isSubmitted = form && form.submitted; |
29 | 26 |
|
30 | 27 | return !!(isInvalid && (isTouched || isSubmitted)); |
31 | 28 | } |
32 | 29 |
|
33 | | -export function showOnDirtyErrorStateMatcher(control: NgControl, formGroup: FormGroupDirective, |
34 | | - form: NgForm): boolean { |
35 | | - |
36 | | - const isInvalid = control && control.invalid; |
37 | | - const isDirty = control && control.dirty; |
38 | | - const isSubmitted = (formGroup && formGroup.submitted) || |
39 | | - (form && form.submitted); |
| 30 | +export function showOnDirtyErrorStateMatcher(control: FormControl, |
| 31 | + form: FormGroupDirective | NgForm) { |
| 32 | + const isInvalid = control.invalid; |
| 33 | + const isDirty = control.dirty; |
| 34 | + const isSubmitted = form && form.submitted; |
40 | 35 |
|
41 | 36 | return !!(isInvalid && (isDirty || isSubmitted)); |
42 | 37 | } |
0 commit comments