@@ -83,12 +83,6 @@ export class MdButtonToggleGroup implements AfterViewInit, ControlValueAccessor
8383 /** onTouch function registered via registerOnTouch (ControlValueAccessor). */
8484 onTouched : ( ) => any = ( ) => { } ;
8585
86- /** Event emitted when the group's value changes. */
87- private _change : EventEmitter < MdButtonToggleChange > = new EventEmitter < MdButtonToggleChange > ( ) ;
88- @Output ( ) get change ( ) : Observable < MdButtonToggleChange > {
89- return this . _change . asObservable ( ) ;
90- }
91-
9286 /** Child button toggle buttons. */
9387 @ContentChildren ( forwardRef ( ( ) => MdButtonToggle ) )
9488 _buttonToggles : QueryList < MdButtonToggle > = null ;
@@ -163,6 +157,12 @@ export class MdButtonToggleGroup implements AfterViewInit, ControlValueAccessor
163157 }
164158 }
165159
160+ /** Event emitted when the group's value changes. */
161+ @Output ( ) get change ( ) : Observable < MdButtonToggleChange > {
162+ return this . _change . asObservable ( ) ;
163+ }
164+ private _change : EventEmitter < MdButtonToggleChange > = new EventEmitter < MdButtonToggleChange > ( ) ;
165+
166166 private _updateButtonToggleNames ( ) : void {
167167 if ( this . _buttonToggles ) {
168168 this . _buttonToggles . forEach ( ( toggle ) => {
@@ -289,15 +289,6 @@ export class MdButtonToggle implements OnInit {
289289 /** Type of the button toggle. Either 'radio' or 'checkbox'. */
290290 _type : ToggleType ;
291291
292- /** The unique ID for this button toggle. */
293- @HostBinding ( )
294- @Input ( )
295- id : string ;
296-
297- /** HTML's 'name' attribute used to group radios for unique selection. */
298- @Input ( )
299- name : string ;
300-
301292 /** Whether or not this button toggle is disabled. */
302293 private _disabled : boolean = null ;
303294
@@ -307,64 +298,28 @@ export class MdButtonToggle implements OnInit {
307298 /** Whether or not the button toggle is a single selection. */
308299 private _isSingleSelector : boolean = null ;
309300
301+ @ViewChild ( 'input' ) _inputElement : ElementRef ;
302+
310303 /** The parent button toggle group (exclusive selection). Optional. */
311304 buttonToggleGroup : MdButtonToggleGroup ;
312305
313306 /** The parent button toggle group (multiple selection). Optional. */
314307 buttonToggleGroupMultiple : MdButtonToggleGroupMultiple ;
315308
316- /** Event emitted when the group value changes. */
317- private _change : EventEmitter < MdButtonToggleChange > = new EventEmitter < MdButtonToggleChange > ( ) ;
318- @Output ( ) get change ( ) : Observable < MdButtonToggleChange > {
319- return this . _change . asObservable ( ) ;
320- }
321-
322- @ViewChild ( 'input' ) _inputElement : ElementRef ;
323-
324- constructor ( @Optional ( ) toggleGroup : MdButtonToggleGroup ,
325- @Optional ( ) toggleGroupMultiple : MdButtonToggleGroupMultiple ,
326- public buttonToggleDispatcher : UniqueSelectionDispatcher ,
327- private _renderer : Renderer ,
328- private _elementRef : ElementRef ,
329- private _focusOriginMonitor : FocusOriginMonitor ) {
330- this . buttonToggleGroup = toggleGroup ;
331-
332- this . buttonToggleGroupMultiple = toggleGroupMultiple ;
333-
334- if ( this . buttonToggleGroup ) {
335- buttonToggleDispatcher . listen ( ( id : string , name : string ) => {
336- if ( id != this . id && name == this . name ) {
337- this . checked = false ;
338- }
339- } ) ;
340-
341- this . _type = 'radio' ;
342- this . name = this . buttonToggleGroup . name ;
343- this . _isSingleSelector = true ;
344- } else {
345- // Even if there is no group at all, treat the button toggle as a checkbox so it can be
346- // toggled on or off.
347- this . _type = 'checkbox' ;
348- this . _isSingleSelector = false ;
349- }
350- }
351-
352- ngOnInit ( ) {
353- if ( this . id == null ) {
354- this . id = `md-button-toggle-${ _uniqueIdCounter ++ } ` ;
355- }
356-
357- if ( this . buttonToggleGroup && this . _value == this . buttonToggleGroup . value ) {
358- this . _checked = true ;
359- }
360- this . _focusOriginMonitor . monitor ( this . _elementRef . nativeElement , this . _renderer , true ) ;
361- }
362-
363309 /** Unique ID for the underlying `input` element. */
364310 get inputId ( ) : string {
365311 return `${ this . id } -input` ;
366312 }
367313
314+ /** The unique ID for this button toggle. */
315+ @HostBinding ( )
316+ @Input ( )
317+ id : string ;
318+
319+ /** HTML's 'name' attribute used to group radios for unique selection. */
320+ @Input ( )
321+ name : string ;
322+
368323 /** Whether the button is checked. */
369324 @HostBinding ( 'class.mat-button-toggle-checked' )
370325 @Input ( )
@@ -376,7 +331,7 @@ export class MdButtonToggle implements OnInit {
376331 if ( this . _isSingleSelector ) {
377332 if ( newCheckedState ) {
378333 // Notify all button toggles with the same name (in the same group) to un-check.
379- this . buttonToggleDispatcher . notify ( this . id , this . name ) ;
334+ this . _buttonToggleDispatcher . notify ( this . id , this . name ) ;
380335 }
381336 }
382337
@@ -402,14 +357,6 @@ export class MdButtonToggle implements OnInit {
402357 }
403358 }
404359
405- /** Dispatch change event with current value. */
406- private _emitChangeEvent ( ) : void {
407- let event = new MdButtonToggleChange ( ) ;
408- event . source = this ;
409- event . value = this . _value ;
410- this . _change . emit ( event ) ;
411- }
412-
413360 /** Whether the button is disabled. */
414361 @HostBinding ( 'class.mat-button-toggle-disabled' )
415362 @Input ( )
@@ -422,6 +369,56 @@ export class MdButtonToggle implements OnInit {
422369 this . _disabled = ( value != null && value !== false ) ? true : null ;
423370 }
424371
372+ /** Event emitted when the group value changes. */
373+ private _change : EventEmitter < MdButtonToggleChange > = new EventEmitter < MdButtonToggleChange > ( ) ;
374+ @Output ( ) get change ( ) : Observable < MdButtonToggleChange > {
375+ return this . _change . asObservable ( ) ;
376+ }
377+
378+ constructor ( @Optional ( ) toggleGroup : MdButtonToggleGroup ,
379+ @Optional ( ) toggleGroupMultiple : MdButtonToggleGroupMultiple ,
380+ private _buttonToggleDispatcher : UniqueSelectionDispatcher ,
381+ private _renderer : Renderer ,
382+ private _elementRef : ElementRef ,
383+ private _focusOriginMonitor : FocusOriginMonitor ) {
384+ this . buttonToggleGroup = toggleGroup ;
385+
386+ this . buttonToggleGroupMultiple = toggleGroupMultiple ;
387+
388+ if ( this . buttonToggleGroup ) {
389+ _buttonToggleDispatcher . listen ( ( id : string , name : string ) => {
390+ if ( id != this . id && name == this . name ) {
391+ this . checked = false ;
392+ }
393+ } ) ;
394+
395+ this . _type = 'radio' ;
396+ this . name = this . buttonToggleGroup . name ;
397+ this . _isSingleSelector = true ;
398+ } else {
399+ // Even if there is no group at all, treat the button toggle as a checkbox so it can be
400+ // toggled on or off.
401+ this . _type = 'checkbox' ;
402+ this . _isSingleSelector = false ;
403+ }
404+ }
405+
406+ ngOnInit ( ) {
407+ if ( this . id == null ) {
408+ this . id = `md-button-toggle-${ _uniqueIdCounter ++ } ` ;
409+ }
410+
411+ if ( this . buttonToggleGroup && this . _value == this . buttonToggleGroup . value ) {
412+ this . _checked = true ;
413+ }
414+ this . _focusOriginMonitor . monitor ( this . _elementRef . nativeElement , this . _renderer , true ) ;
415+ }
416+
417+ /** Focuses the button. */
418+ focus ( ) {
419+ this . _renderer . invokeElementMethod ( this . _inputElement . nativeElement , 'focus' ) ;
420+ }
421+
425422 /** Toggle the state of the current button toggle. */
426423 private _toggle ( ) : void {
427424 this . checked = ! this . checked ;
@@ -456,8 +453,11 @@ export class MdButtonToggle implements OnInit {
456453 event . stopPropagation ( ) ;
457454 }
458455
459- /** Focuses the button. */
460- focus ( ) {
461- this . _renderer . invokeElementMethod ( this . _inputElement . nativeElement , 'focus' ) ;
456+ /** Dispatch change event with current value. */
457+ private _emitChangeEvent ( ) : void {
458+ let event = new MdButtonToggleChange ( ) ;
459+ event . source = this ;
460+ event . value = this . _value ;
461+ this . _change . emit ( event ) ;
462462 }
463463}
0 commit comments