@@ -13,13 +13,16 @@ import {
1313 ElementRef ,
1414 QueryList ,
1515 OnChanges ,
16+ EventEmitter ,
17+ Output ,
1618} from '@angular/core' ;
1719import {
1820 NG_VALUE_ACCESSOR ,
1921 ControlValueAccessor
2022} from '@angular/common' ;
2123import { BooleanFieldValue } from '../../core/annotations/field-value' ;
2224import { MdError } from '../../core/errors/error' ;
25+ import { Observable } from 'rxjs/Observable' ;
2326
2427
2528const noop = ( ) => { } ;
@@ -142,6 +145,19 @@ export class MdInput implements ControlValueAccessor, AfterContentInit, OnChange
142145 @Input ( ) @BooleanFieldValue ( ) spellcheck : boolean = false ;
143146 @Input ( ) type : string = 'text' ;
144147
148+ private _blurEmitter : EventEmitter < FocusEvent > = new EventEmitter < FocusEvent > ( ) ;
149+ private _focusEmitter : EventEmitter < FocusEvent > = new EventEmitter < FocusEvent > ( ) ;
150+
151+ @Output ( 'blur' )
152+ get onBlur ( ) : Observable < FocusEvent > {
153+ return this . _blurEmitter . asObservable ( ) ;
154+ }
155+
156+ @Output ( 'focus' )
157+ get onFocus ( ) : Observable < FocusEvent > {
158+ return this . _focusEmitter . asObservable ( ) ;
159+ }
160+
145161 get value ( ) : any { return this . _value ; } ;
146162 @Input ( ) set value ( v : any ) {
147163 v = this . _convertValueForInputType ( v ) ;
@@ -165,17 +181,21 @@ export class MdInput implements ControlValueAccessor, AfterContentInit, OnChange
165181 }
166182
167183 /** @internal */
168- onFocus ( ) {
184+ handleFocus ( event : FocusEvent ) {
169185 this . _focused = true ;
186+ this . _focusEmitter . emit ( event ) ;
170187 }
188+
171189 /** @internal */
172- onBlur ( ) {
190+ handleBlur ( event : FocusEvent ) {
173191 this . _focused = false ;
174192 this . _onTouchedCallback ( ) ;
193+ this . _blurEmitter . emit ( event ) ;
175194 }
195+
176196 /** @internal */
177- onChange ( ev : Event ) {
178- this . value = ( < HTMLInputElement > ev . target ) . value ;
197+ handleChange ( event : Event ) {
198+ this . value = ( < HTMLInputElement > event . target ) . value ;
179199 this . _onTouchedCallback ( ) ;
180200 }
181201
0 commit comments