@@ -135,11 +135,11 @@ export class MdInputDirective implements AfterContentInit {
135135
136136 constructor ( private _elementRef : ElementRef ,
137137 private _renderer : Renderer ,
138- @Optional ( ) private _ngControl : NgControl ) {
138+ @Optional ( ) public _ngControl : NgControl ) {
139139 // Force setter to be called in case id was not specified.
140140 this . id = this . id ;
141141
142- if ( this . _ngControl ) {
142+ if ( this . _ngControl && this . _ngControl . valueChanges ) {
143143 this . _ngControl . valueChanges . subscribe ( ( value ) => {
144144 this . value = value ;
145145 } ) ;
@@ -182,6 +182,13 @@ export class MdInputDirective implements AfterContentInit {
182182 host : {
183183 // Remove align attribute to prevent it from interfering with layout.
184184 '[attr.align]' : 'null' ,
185+ '[class.ng-untouched]' : '_isUntouched()' ,
186+ '[class.ng-touched]' : '_isTouched()' ,
187+ '[class.ng-pristine]' : '_isPristine()' ,
188+ '[class.ng-dirty]' : '_isDirty()' ,
189+ '[class.ng-valid]' : '_isValid()' ,
190+ '[class.ng-invalid]' : '_isInvalid()' ,
191+ '[class.ng-pending]' : '_isPending()' ,
185192 '(click)' : '_focusInput()' ,
186193 } ,
187194 encapsulation : ViewEncapsulation . None ,
@@ -223,13 +230,27 @@ export class MdInputContainer implements AfterContentInit {
223230 } ) ;
224231 }
225232
233+ _isUntouched ( ) { return this . _hasNgControl ( ) && this . _mdInputChild . _ngControl . untouched ; }
234+
235+ _isTouched ( ) { return this . _hasNgControl ( ) && this . _mdInputChild . _ngControl . touched ; }
236+
237+ _isPristine ( ) { return this . _hasNgControl ( ) && this . _mdInputChild . _ngControl . pristine ; }
238+
239+ _isDirty ( ) { return this . _hasNgControl ( ) && this . _mdInputChild . _ngControl . dirty ; }
240+
241+ _isValid ( ) { return this . _hasNgControl ( ) && this . _mdInputChild . _ngControl . valid ; }
242+
243+ _isInvalid ( ) { return this . _hasNgControl ( ) && this . _mdInputChild . _ngControl . invalid ; }
244+
245+ _isPending ( ) { return this . _hasNgControl ( ) && this . _mdInputChild . _ngControl . pending ; }
246+
226247 /** Whether the input has a placeholder. */
227- _hasPlaceholder ( ) : boolean {
228- return ! ! this . _mdInputChild . placeholder || ! ! this . _placeholderChild ;
229- }
248+ _hasPlaceholder ( ) { return ! ! ( this . _mdInputChild . placeholder || this . _placeholderChild ) ; }
230249
231250 _focusInput ( ) { this . _mdInputChild . focus ( ) ; }
232251
252+ private _hasNgControl ( ) { return ! ! ( this . _mdInputChild && this . _mdInputChild . _ngControl ) ; }
253+
233254 /**
234255 * Ensure that there is only one placeholder (either `input` attribute or child element with the
235256 * `md-placeholder` attribute.
0 commit comments