@@ -18,7 +18,7 @@ import {
1818import {
1919 NG_VALUE_ACCESSOR ,
2020 ControlValueAccessor ,
21- FormsModule
21+ FormsModule , FormGroupName
2222} from '@angular/forms' ;
2323import { CommonModule } from '@angular/common' ;
2424import { BooleanProperty } from '../common/boolean-property' ;
@@ -34,13 +34,13 @@ const IS_FOCUSED = 'is-focused';
3434@Injectable ( )
3535export class MdlRadioGroupRegisty {
3636
37- private defaultRadioGroup = new MdlRadioGroup ( ) ;
38- private radioComponents : { radio : MdlRadioComponent , group :MdlRadioGroup } [ ] = [ ] ;
37+ private defaultFormGroup = 'defaultFromGroup' ;
38+ private radioComponents : { radio : MdlRadioComponent , group : FormGroupName | string } [ ] = [ ] ;
3939
40- public add ( radioComponent : MdlRadioComponent , mdlRadioGroup : MdlRadioGroup ) {
40+ public add ( radioComponent : MdlRadioComponent , formGroupName : FormGroupName ) {
4141 this . radioComponents . push ( {
4242 radio : radioComponent ,
43- group : mdlRadioGroup || this . defaultRadioGroup
43+ group : formGroupName || this . defaultFormGroup
4444 } ) ;
4545 }
4646
@@ -50,12 +50,12 @@ export class MdlRadioGroupRegisty {
5050 } ) ;
5151 }
5252
53- public select ( radioComponent : MdlRadioComponent , mdlRadioGroup : MdlRadioGroup ) {
53+ public select ( radioComponent : MdlRadioComponent , formGroupName : FormGroupName ) {
5454 // unselect every radioComponent that is not the provided radiocomponent
5555 // and has the same name and is in teh same group.
56- let testGroup = mdlRadioGroup || this . defaultRadioGroup ;
56+ let groupToTest = formGroupName || this . defaultFormGroup ;
5757 this . radioComponents . forEach ( ( component ) => {
58- if ( component . radio . name === radioComponent . name && component . group === testGroup ) {
58+ if ( component . radio . name === radioComponent . name && component . group === groupToTest ) {
5959 if ( component . radio !== radioComponent ) {
6060 component . radio . deselect ( radioComponent . value ) ;
6161 }
@@ -64,12 +64,6 @@ export class MdlRadioGroupRegisty {
6464 }
6565}
6666
67- @Directive ( {
68- selector : '[formGroupName][mdl-radio-group]'
69- } )
70- export class MdlRadioGroup {
71- }
72-
7367/*
7468 <mdl-radio name="group1" value="1" [(ngModel)]="radioOption">Value 1</mdl-radio>
7569 */
@@ -123,7 +117,7 @@ export class MdlRadioComponent implements ControlValueAccessor, OnInit, OnDestro
123117 private elementRef : ElementRef ,
124118 private renderer : Renderer ,
125119 private ragioGroupRegisty : MdlRadioGroupRegisty ,
126- @Optional ( ) private mdlRadioGroup : MdlRadioGroup ) {
120+ @Optional ( ) private formGroupName : FormGroupName ) {
127121 this . el = elementRef . nativeElement ;
128122 }
129123
@@ -132,8 +126,9 @@ export class MdlRadioComponent implements ControlValueAccessor, OnInit, OnDestro
132126 // a radio group without name is useless.
133127 this . checkName ( ) ;
134128 // register the radio button - this is the only chance to unselect the
135- // radio button that is no longer active
136- this . ragioGroupRegisty . add ( this , this . mdlRadioGroup ) ;
129+ // radio button that is no longer active - scope the radio button with it's group
130+ // if there is one.
131+ this . ragioGroupRegisty . add ( this , this . formGroupName ) ;
137132 }
138133
139134 public ngOnDestroy ( ) {
@@ -155,7 +150,7 @@ export class MdlRadioComponent implements ControlValueAccessor, OnInit, OnDestro
155150 // wrap the callback, so that we can call select on the registry
156151 this . onChangeCallback = ( ) => {
157152 fn ( this . value ) ;
158- this . ragioGroupRegisty . select ( this , this . mdlRadioGroup ) ;
153+ this . ragioGroupRegisty . select ( this , this . formGroupName ) ;
159154 } ;
160155 }
161156
@@ -209,8 +204,8 @@ export class MdlRadioComponent implements ControlValueAccessor, OnInit, OnDestro
209204
210205@NgModule ( {
211206 imports : [ CommonModule , FormsModule ] ,
212- exports : [ MdlRadioComponent , MdlRadioGroup ] ,
213- declarations : [ MdlRadioComponent , MdlRadioGroup ]
207+ exports : [ MdlRadioComponent ] ,
208+ declarations : [ MdlRadioComponent ]
214209} )
215210export class MdlRadioModule {
216211 public static forRoot ( ) : ModuleWithProviders {
0 commit comments