@@ -69,7 +69,7 @@ export class MdRadioGroup implements AfterContentInit, ControlValueAccessor {
6969 private _value : any = null ;
7070
7171 /** The HTML name attribute applied to radio buttons in this group. */
72- private _name : string = null ;
72+ private _name : string = `md-radio-group- ${ _uniqueIdCounter ++ } ` ;
7373
7474 /** Disables all individual radio buttons assigned to this group. */
7575 private _disabled : boolean = false ;
@@ -101,14 +101,7 @@ export class MdRadioGroup implements AfterContentInit, ControlValueAccessor {
101101
102102 set name ( value : string ) {
103103 this . _name = value ;
104- this . _updateChildRadioNames ( ) ;
105- }
106-
107- /** Propagate name attribute to radio buttons. */
108- private _updateChildRadioNames ( ) : void {
109- ( this . _radios || [ ] ) . forEach ( radio => {
110- radio . name = this . _name ;
111- } ) ;
104+ this . _updateRadioButtonNames ( ) ;
112105 }
113106
114107 @Input ( )
@@ -160,10 +153,6 @@ export class MdRadioGroup implements AfterContentInit, ControlValueAccessor {
160153 * @internal
161154 */
162155 ngAfterContentInit ( ) {
163- if ( ! this . _name ) {
164- this . name = `md-radio-group-${ _uniqueIdCounter ++ } ` ;
165- }
166-
167156 // Mark this component as initialized in AfterContentInit because the initial value can
168157 // possibly be set by NgModel on MdRadioGroup, and it is possible that the OnInit of the
169158 // NgModel occurs *after* the OnInit of the MdRadioGroup.
@@ -181,9 +170,15 @@ export class MdRadioGroup implements AfterContentInit, ControlValueAccessor {
181170 }
182171 }
183172
173+ private _updateRadioButtonNames ( ) : void {
174+ ( this . _radios || [ ] ) . forEach ( radio => {
175+ radio . name = this . name ;
176+ } ) ;
177+ }
178+
184179 /** Updates the `selected` radio button from the internal _value state. */
185180 private _updateSelectedRadioFromValue ( ) : void {
186- // If the value already matches the selected radio, no dothing .
181+ // If the value already matches the selected radio, do nothing .
187182 let isAlreadySelected = this . _selected != null && this . _selected . value == this . _value ;
188183
189184 if ( this . _radios != null && ! isAlreadySelected ) {
@@ -192,8 +187,8 @@ export class MdRadioGroup implements AfterContentInit, ControlValueAccessor {
192187 if ( matchingRadio ) {
193188 this . selected = matchingRadio ;
194189 } else if ( this . value == null ) {
195- this . selected = null ;
196- this . _radios . forEach ( radio => { radio . checked = false ; } ) ;
190+ this . selected = null ;
191+ this . _radios . forEach ( radio => { radio . checked = false ; } ) ;
197192 }
198193 }
199194 }
@@ -206,7 +201,7 @@ export class MdRadioGroup implements AfterContentInit, ControlValueAccessor {
206201 this . change . emit ( event ) ;
207202 }
208203
209- /**
204+ /**
210205 * Implemented as part of ControlValueAccessor.
211206 * @internal
212207 */
@@ -258,7 +253,7 @@ export class MdRadioButton implements OnInit {
258253 /** The unique ID for the radio button. */
259254 @HostBinding ( 'id' )
260255 @Input ( )
261- id : string ;
256+ id : string = `md-radio- ${ _uniqueIdCounter ++ } ` ;
262257
263258 /** Analog to HTML 'name' attribute used to group radios for unique selection. */
264259 @Input ( )
@@ -345,15 +340,11 @@ export class MdRadioButton implements OnInit {
345340
346341 /** @internal */
347342 ngOnInit ( ) {
348- // All radio buttons must have a unique id.
349- if ( ! this . id ) {
350- this . id = `md-radio-${ _uniqueIdCounter ++ } ` ;
351- }
352-
353- // If the radio is inside of a radio group and it matches that group's value upon
354- // initialization, start off as checked.
355- if ( this . radioGroup && this . radioGroup . value === this . _value ) {
356- this . checked = true ;
343+ if ( this . radioGroup ) {
344+ // If the radio is inside a radio group, determine if it should be checked
345+ this . checked = this . radioGroup . value === this . _value ;
346+ // Copy name from parent radio group
347+ this . name = this . radioGroup . name ;
357348 }
358349 }
359350
0 commit comments