Skip to content

Commit 00175eb

Browse files
committed
chore: added event to docs and provided angular example of usage
1 parent bb4f30f commit 00175eb

File tree

4 files changed

+57
-48
lines changed

4 files changed

+57
-48
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ export class SomeComponent {
9898
- **text** - text to use with the checkbox
9999
- **fillColor** - Color of the checkbox element
100100

101+
## Events
102+
103+
- **checkedChange** - Use a reference to the CheckBox component to grab it's `checked` property when this event fires to see the new value.
104+
101105
## API
102106

103107
- **toggle()** - Change the checked state of the view to the inverse of its current state.

demo-ng/app/item/items.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<StackLayout *tabItem="{title: 'Checkboxes'}">
88
<StackLayout class="page">
99
<StackLayout orientation="horizontal" class="p-10">
10-
<CheckBox #modelCheck [(ngModel)]="checkTest" class="checkbox"></CheckBox>
10+
<CheckBox #modelCheck [(ngModel)]="checkTest" class="checkbox" (checkedChange)="checkedChange(modelCheck)"></CheckBox>
1111
<Label text="Test NgModel" (tap)="modelCheck.toggle()"></Label>
1212
</StackLayout>
1313
<StackLayout class="form-group" [formGroup]="formGroup" orientation="horizontal" class="p-10">

demo-ng/app/item/items.component.ts

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,61 +6,66 @@ import { ItemService } from "./item.service";
66
import { RadioOption } from "./radio-option";
77

88
@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"
1212
})
1313
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>;
1818

19-
constructor(
20-
private formBuilder: FormBuilder,
21-
private itemService: ItemService
22-
) { }
19+
constructor(
20+
private formBuilder: FormBuilder,
21+
private itemService: ItemService
22+
) {}
2323

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+
});
3634

37-
this.items = this.itemService.getItems();
35+
this.items = this.itemService.getItems();
3836

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+
}
4644

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+
}
5148

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+
}
5456

55-
if (!radioOption.selected) {
56-
return;
57-
}
57+
changeCheckedRadio(radioOption: RadioOption): void {
58+
radioOption.selected = !radioOption.selected;
5859

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;
6562
}
63+
64+
// uncheck all other options
65+
this.radioOptions.forEach(option => {
66+
if (option.text !== radioOption.text) {
67+
option.selected = false;
68+
}
69+
});
70+
}
6671
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-checkbox",
3-
"version": "2.1.8",
3+
"version": "2.1.10",
44
"description": "NativeScript plugin for checkbox widget.",
55
"main": "checkbox",
66
"typings": "index.d.ts",

0 commit comments

Comments
 (0)