@@ -10,11 +10,17 @@ import {
10
10
ViewEncapsulation ,
11
11
Optional ,
12
12
Output ,
13
- EventEmitter
13
+ EventEmitter ,
14
+ Renderer
14
15
} from '@angular/core' ;
15
- import { MdError , coerceBooleanProperty } from '../core' ;
16
+ import { coerceBooleanProperty } from '../core' ;
16
17
import { NgModel } from '@angular/forms' ;
17
18
import { MdFeatureDetector } from '../core/platform/feature-detector' ;
19
+ import {
20
+ MdInputWrapperUnsupportedTypeError ,
21
+ MdInputWrapperPlaceholderConflictError ,
22
+ MdInputWrapperDuplicatedHintError
23
+ } from './input-wrapper-errors' ;
18
24
19
25
20
26
// Invalid input type. Using one of these will throw an MdInputWrapperUnsupportedTypeError.
@@ -35,27 +41,6 @@ const MD_INPUT_INVALID_TYPES = [
35
41
let nextUniqueId = 0 ;
36
42
37
43
38
- export class MdInputWrapperPlaceholderConflictError extends MdError {
39
- constructor ( ) {
40
- super ( 'Placeholder attribute and child element were both specified.' ) ;
41
- }
42
- }
43
-
44
-
45
- export class MdInputWrapperUnsupportedTypeError extends MdError {
46
- constructor ( type : string ) {
47
- super ( `Input type "${ type } " isn't supported by md-input-wrapper.` ) ;
48
- }
49
- }
50
-
51
-
52
- export class MdInputWrapperDuplicatedHintError extends MdError {
53
- constructor ( align : string ) {
54
- super ( `A hint was already declared for 'align="${ align } "'.` ) ;
55
- }
56
- }
57
-
58
-
59
44
/**
60
45
* The placeholder directive. The content can declare this to implement more
61
46
* complex placeholders.
@@ -107,7 +92,7 @@ export class MdInputDirective implements AfterContentInit {
107
92
set placeholder ( value : string ) {
108
93
if ( this . _placeholder != value ) {
109
94
this . _placeholder = value ;
110
- this . placeholderChange . emit ( this . _placeholder ) ;
95
+ this . _placeholderChange . emit ( this . _placeholder ) ;
111
96
}
112
97
}
113
98
private _placeholder = '' ;
@@ -125,10 +110,10 @@ export class MdInputDirective implements AfterContentInit {
125
110
}
126
111
private _type = 'text' ;
127
112
128
- @Input ( )
129
113
value : any ;
130
114
131
- @Output ( ) placeholderChange = new EventEmitter < string > ( ) ;
115
+ /** Emits an event when the placeholder changes so that the `md-input-wrapper` can re-validate. */
116
+ @Output ( ) _placeholderChange = new EventEmitter < string > ( ) ;
132
117
133
118
get empty ( ) { return ( this . value == null || this . value == '' ) && ! this . _isNeverEmpty ( ) ; }
134
119
@@ -148,6 +133,7 @@ export class MdInputDirective implements AfterContentInit {
148
133
149
134
constructor ( private _featureDetector : MdFeatureDetector ,
150
135
private _elementRef : ElementRef ,
136
+ private _renderer : Renderer ,
151
137
@Optional ( ) private _ngModel : NgModel ) {
152
138
// Force setter to be called in case id was not specified.
153
139
this . id = this . id ;
@@ -164,7 +150,7 @@ export class MdInputDirective implements AfterContentInit {
164
150
}
165
151
166
152
/** Focus the input element. */
167
- focus ( ) { this . _elementRef . nativeElement . focus ( ) ; }
153
+ focus ( ) { this . _renderer . invokeElementMethod ( this . _elementRef . nativeElement , ' focus' ) ; }
168
154
169
155
/** Make sure the input is a supported type. */
170
156
private _validateType ( ) {
@@ -231,7 +217,7 @@ export class MdInputWrapper implements AfterContentInit {
231
217
this . _hintChildren . changes . subscribe ( ( ) => {
232
218
this . _validateHints ( ) ;
233
219
} ) ;
234
- this . _mdInputChild . placeholderChange . subscribe ( ( ) => {
220
+ this . _mdInputChild . _placeholderChange . subscribe ( ( ) => {
235
221
this . _validatePlaceholders ( ) ;
236
222
} ) ;
237
223
}
0 commit comments