@@ -6,61 +6,66 @@ import { ItemService } from "./item.service";
6
6
import { RadioOption } from "./radio-option" ;
7
7
8
8
@Component ( {
9
- selector : "ns-items" ,
10
- moduleId : module . id ,
11
- templateUrl : "./items.component.html" ,
9
+ selector : "ns-items" ,
10
+ moduleId : module . id ,
11
+ templateUrl : "./items.component.html"
12
12
} )
13
13
export class ItemsComponent implements OnInit {
14
- formGroup : FormGroup ;
15
- checkTest : boolean ;
16
- items : Item [ ] ;
17
- radioOptions ?: Array < RadioOption > ;
14
+ formGroup : FormGroup ;
15
+ checkTest : boolean ;
16
+ items : Item [ ] ;
17
+ radioOptions ?: Array < RadioOption > ;
18
18
19
- constructor (
20
- private formBuilder : FormBuilder ,
21
- private itemService : ItemService
22
- ) { }
19
+ constructor (
20
+ private formBuilder : FormBuilder ,
21
+ private itemService : ItemService
22
+ ) { }
23
23
24
- ngOnInit ( ) : void {
25
- this . formGroup = this . formBuilder . group ( {
26
- testCheck : [
27
- {
28
- value : true ,
29
- disabled : false ,
30
- } ,
31
- [
32
- Validators . required
33
- ] ,
34
- ]
35
- } ) ;
24
+ ngOnInit ( ) : void {
25
+ this . formGroup = this . formBuilder . group ( {
26
+ testCheck : [
27
+ {
28
+ value : true ,
29
+ disabled : false
30
+ } ,
31
+ [ Validators . required ]
32
+ ]
33
+ } ) ;
36
34
37
- this . items = this . itemService . getItems ( ) ;
35
+ this . items = this . itemService . getItems ( ) ;
38
36
39
- // Plain ol' inline Array definition coming up :)
40
- this . radioOptions = [
41
- new RadioOption ( "Radio option 1" ) ,
42
- new RadioOption ( "Radio option 2" ) ,
43
- new RadioOption ( "Radio option 3" )
44
- ] ;
45
- }
37
+ // Plain ol' inline Array definition coming up :)
38
+ this . radioOptions = [
39
+ new RadioOption ( "Radio option 1" ) ,
40
+ new RadioOption ( "Radio option 2" ) ,
41
+ new RadioOption ( "Radio option 3" )
42
+ ] ;
43
+ }
46
44
47
- public submit ( ) {
48
- console . log ( 'NgModel value:' , this . checkTest ) ;
49
- console . log ( 'Reactive FormGroup value:' , this . formGroup . get ( 'testCheck' ) . value ) ;
50
- }
45
+ public checkedChange ( modelRef ) {
46
+ console . log ( "checkedChange:" , modelRef . checked ) ;
47
+ }
51
48
52
- changeCheckedRadio ( radioOption : RadioOption ) : void {
53
- radioOption . selected = ! radioOption . selected ;
49
+ public submit ( ) {
50
+ console . log ( "NgModel value:" , this . checkTest ) ;
51
+ console . log (
52
+ "Reactive FormGroup value:" ,
53
+ this . formGroup . get ( "testCheck" ) . value
54
+ ) ;
55
+ }
54
56
55
- if ( ! radioOption . selected ) {
56
- return ;
57
- }
57
+ changeCheckedRadio ( radioOption : RadioOption ) : void {
58
+ radioOption . selected = ! radioOption . selected ;
58
59
59
- // uncheck all other options
60
- this . radioOptions . forEach ( option => {
61
- if ( option . text !== radioOption . text ) {
62
- option . selected = false ;
63
- }
64
- } ) ;
60
+ if ( ! radioOption . selected ) {
61
+ return ;
65
62
}
63
+
64
+ // uncheck all other options
65
+ this . radioOptions . forEach ( option => {
66
+ if ( option . text !== radioOption . text ) {
67
+ option . selected = false ;
68
+ }
69
+ } ) ;
70
+ }
66
71
}
0 commit comments