@@ -135,11 +135,11 @@ export class MdInputDirective implements AfterContentInit {
135
135
136
136
constructor ( private _elementRef : ElementRef ,
137
137
private _renderer : Renderer ,
138
- @Optional ( ) private _ngControl : NgControl ) {
138
+ @Optional ( ) public _ngControl : NgControl ) {
139
139
// Force setter to be called in case id was not specified.
140
140
this . id = this . id ;
141
141
142
- if ( this . _ngControl ) {
142
+ if ( this . _ngControl && this . _ngControl . valueChanges ) {
143
143
this . _ngControl . valueChanges . subscribe ( ( value ) => {
144
144
this . value = value ;
145
145
} ) ;
@@ -182,6 +182,13 @@ export class MdInputDirective implements AfterContentInit {
182
182
host : {
183
183
// Remove align attribute to prevent it from interfering with layout.
184
184
'[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()' ,
185
192
'(click)' : '_focusInput()' ,
186
193
} ,
187
194
encapsulation : ViewEncapsulation . None ,
@@ -223,13 +230,27 @@ export class MdInputContainer implements AfterContentInit {
223
230
} ) ;
224
231
}
225
232
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
+
226
247
/** 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 ) ; }
230
249
231
250
_focusInput ( ) { this . _mdInputChild . focus ( ) ; }
232
251
252
+ private _hasNgControl ( ) { return ! ! ( this . _mdInputChild && this . _mdInputChild . _ngControl ) ; }
253
+
233
254
/**
234
255
* Ensure that there is only one placeholder (either `input` attribute or child element with the
235
256
* `md-placeholder` attribute.
0 commit comments