@@ -214,13 +214,13 @@ export class MdInputDirective {
214
214
host : {
215
215
// Remove align attribute to prevent it from interfering with layout.
216
216
'[attr.align]' : 'null' ,
217
- '[class.ng-untouched]' : '_isUntouched( )' ,
218
- '[class.ng-touched]' : '_isTouched( )' ,
219
- '[class.ng-pristine]' : '_isPristine( )' ,
220
- '[class.ng-dirty]' : '_isDirty( )' ,
221
- '[class.ng-valid]' : '_isValid( )' ,
222
- '[class.ng-invalid]' : '_isInvalid( )' ,
223
- '[class.ng-pending]' : '_isPending( )' ,
217
+ '[class.ng-untouched]' : '_shouldForward("untouched" )' ,
218
+ '[class.ng-touched]' : '_shouldForward("touched" )' ,
219
+ '[class.ng-pristine]' : '_shouldForward("pristine" )' ,
220
+ '[class.ng-dirty]' : '_shouldForward("dirty" )' ,
221
+ '[class.ng-valid]' : '_shouldForward("valid" )' ,
222
+ '[class.ng-invalid]' : '_shouldForward("invalid" )' ,
223
+ '[class.ng-pending]' : '_shouldForward("pending" )' ,
224
224
'(click)' : '_focusInput()' ,
225
225
} ,
226
226
encapsulation : ViewEncapsulation . None ,
@@ -262,35 +262,21 @@ export class MdInputContainer implements AfterContentInit {
262
262
this . _validatePlaceholders ( ) ;
263
263
264
264
// Re-validate when things change.
265
- this . _hintChildren . changes . subscribe ( ( ) => {
266
- this . _validateHints ( ) ;
267
- } ) ;
268
- this . _mdInputChild . _placeholderChange . subscribe ( ( ) => {
269
- this . _validatePlaceholders ( ) ;
270
- } ) ;
265
+ this . _hintChildren . changes . subscribe ( ( ) => this . _validateHints ( ) ) ;
266
+ this . _mdInputChild . _placeholderChange . subscribe ( ( ) => this . _validatePlaceholders ( ) ) ;
271
267
}
272
268
273
- _isUntouched ( ) { return this . _hasNgControl ( ) && this . _mdInputChild . _ngControl . untouched ; }
274
-
275
- _isTouched ( ) { return this . _hasNgControl ( ) && this . _mdInputChild . _ngControl . touched ; }
276
-
277
- _isPristine ( ) { return this . _hasNgControl ( ) && this . _mdInputChild . _ngControl . pristine ; }
278
-
279
- _isDirty ( ) { return this . _hasNgControl ( ) && this . _mdInputChild . _ngControl . dirty ; }
280
-
281
- _isValid ( ) { return this . _hasNgControl ( ) && this . _mdInputChild . _ngControl . valid ; }
282
-
283
- _isInvalid ( ) { return this . _hasNgControl ( ) && this . _mdInputChild . _ngControl . invalid ; }
284
-
285
- _isPending ( ) { return this . _hasNgControl ( ) && this . _mdInputChild . _ngControl . pending ; }
269
+ /** Determines whether a class from the NgControl should be forwarded to the host element. */
270
+ _shouldForward ( prop : string ) : boolean {
271
+ let control = this . _mdInputChild ? this . _mdInputChild . _ngControl : null ;
272
+ return control && ( control as any ) [ prop ] ;
273
+ }
286
274
287
275
/** Whether the input has a placeholder. */
288
276
_hasPlaceholder ( ) { return ! ! ( this . _mdInputChild . placeholder || this . _placeholderChild ) ; }
289
277
290
278
_focusInput ( ) { this . _mdInputChild . focus ( ) ; }
291
279
292
- private _hasNgControl ( ) { return ! ! ( this . _mdInputChild && this . _mdInputChild . _ngControl ) ; }
293
-
294
280
/**
295
281
* Ensure that there is only one placeholder (either `input` attribute or child element with the
296
282
* `md-placeholder` attribute.
0 commit comments