@@ -10,7 +10,6 @@ import {
1010 Directive ,
1111 DoCheck ,
1212 ElementRef ,
13- Inject ,
1413 Input ,
1514 OnChanges ,
1615 OnDestroy ,
@@ -19,15 +18,10 @@ import {
1918 Self ,
2019} from '@angular/core' ;
2120import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
22- import { FormControl , FormGroupDirective , NgControl , NgForm } from '@angular/forms' ;
21+ import { FormGroupDirective , NgControl , NgForm } from '@angular/forms' ;
2322import { Platform , getSupportedInputTypes } from '@angular/cdk/platform' ;
2423import { getMatInputUnsupportedTypeError } from './input-errors' ;
25- import {
26- defaultErrorStateMatcher ,
27- ErrorOptions ,
28- ErrorStateMatcher ,
29- MAT_ERROR_GLOBAL_OPTIONS
30- } from '@angular/material/core' ;
24+ import { ErrorStateMatcher } from '@angular/material/core' ;
3125import { Subject } from 'rxjs/Subject' ;
3226import { MatFormFieldControl } from '@angular/material/form-field' ;
3327
@@ -74,7 +68,6 @@ export class MatInput implements MatFormFieldControl<any>, OnChanges, OnDestroy,
7468 protected _required = false ;
7569 protected _id : string ;
7670 protected _uid = `mat-input-${ nextUniqueId ++ } ` ;
77- protected _errorOptions : ErrorOptions ;
7871 protected _previousNativeValue = this . value ;
7972 private _readonly = false ;
8073
@@ -129,7 +122,7 @@ export class MatInput implements MatFormFieldControl<any>, OnChanges, OnDestroy,
129122 }
130123 }
131124
132- /** A function used to control when error messages are shown. */
125+ /** An object used to control when error messages are shown. */
133126 @Input ( ) errorStateMatcher : ErrorStateMatcher ;
134127
135128 /** The input element's value. */
@@ -162,12 +155,10 @@ export class MatInput implements MatFormFieldControl<any>, OnChanges, OnDestroy,
162155 @Optional ( ) @Self ( ) public ngControl : NgControl ,
163156 @Optional ( ) protected _parentForm : NgForm ,
164157 @Optional ( ) protected _parentFormGroup : FormGroupDirective ,
165- @ Optional ( ) @ Inject ( MAT_ERROR_GLOBAL_OPTIONS ) errorOptions : ErrorOptions ) {
158+ private _defaultErrorStateMatcher : ErrorStateMatcher ) {
166159
167160 // Force setter to be called in case id was not specified.
168161 this . id = this . id ;
169- this . _errorOptions = errorOptions ? errorOptions : { } ;
170- this . errorStateMatcher = this . _errorOptions . errorStateMatcher || defaultErrorStateMatcher ;
171162
172163 // On some versions of iOS the caret gets stuck in the wrong place when holding down the delete
173164 // key. In order to get around this we need to "jiggle" the caret loose. Since this bug only
@@ -230,9 +221,9 @@ export class MatInput implements MatFormFieldControl<any>, OnChanges, OnDestroy,
230221 /** Re-evaluates the error state. This is only relevant with @angular/forms. */
231222 protected _updateErrorState ( ) {
232223 const oldState = this . errorState ;
233- const ngControl = this . ngControl ;
234224 const parent = this . _parentFormGroup || this . _parentForm ;
235- const newState = ngControl && this . errorStateMatcher ( ngControl . control as FormControl , parent ) ;
225+ const matcher = this . errorStateMatcher || this . _defaultErrorStateMatcher ;
226+ const newState = matcher . isErrorState ( this . ngControl , parent ) ;
236227
237228 if ( newState !== oldState ) {
238229 this . errorState = newState ;
0 commit comments