nstudio / nativescript-checkbox

NativeScript plugin for checkbox UI component
Other
119 stars 56 forks source link

ngModel not working #13

Closed aboalwi closed 7 years ago

aboalwi commented 8 years ago

I need to update the checked value in array If i use [checked] instead it wont be updated will always be false unless i have some way to update the array element based on the nativeElement value :/

    public categories = [
      {catid: 1, name: 'Electronics', checked: false},
      {catid: 2, name: 'Furnitures', checked: false},
      {catid: 3, name: 'Home Appliance', checked: false},
      {catid: 4, name: 'Games', checked: false},
      {catid: 5, name: 'Accessories', checked: false}
    ]; 
    <StackLayout *ngFor="let cat of categories">
        <CheckBox [text]="cat.name" [(ngModel)]="cat.checked"></CheckBox>
        <Label [text]="cat.checked"></Label>
    </StackLayout> 
JS: EXCEPTION: Error in pages/categories/categories.html:24:36 caused by: No value accessor for form control with unspecified name attribute
JS: ORIGINAL EXCEPTION: No value accessor for form control with unspecified name attribute
bradmartin commented 8 years ago

I've not gotten into angular w/ nativescript to know enough here. I'll see if @NathanWalker or @triniwiz have a clue from the sample you provided.

triniwiz commented 8 years ago

@bradmartin i never used ngModel the app simply uses [checked]="someVal"

devna13 commented 7 years ago

Same problem here.

@triniwiz That's one way binding and binding property never changes when clicking the checkbox.

Have to use some other UI element due to this issue.

triniwiz commented 7 years ago

@devna13 i handle changes with (checkedChange)="doSomething($event)"

devna13 commented 7 years ago

@triniwiz are you sure!? There is no event called checkedChange.

triniwiz commented 7 years ago
<CheckBox [checked]="item.completed" text=""  (checkedChange)="itemChecked($event)"></CheckBox>

itemChecked(event){
let checked = event.value;
this.item.completed = value;
}

it's simple as above and this works because i am currently using this atm

baretka commented 5 years ago
<CheckBox [checked]="item.completed" text=""  (checkedChange)="itemChecked($event)"></CheckBox>

itemChecked(event){
let checked = event.value;
this.item.completed = value;
}

it's simple as above and this works because i am currently using this atm

Thanks