简体   繁体   中英

Not able to click nb-checkbox of Nebular theme angular

I am new to Nebular theme. I have a checkbox but it's not working.

HTML

<nb-checkbox [value]="checked" (change)="toggle($event)"></nb-checkbox>

TypeScript

  toggle(checked: any) {    
    this.checked = checked.target.checked;
  }

Module.ts

//import
import { NbCheckboxModule } from '@nebular/theme';

imports: [NbCheckboxModule]

toggle function is being called fine but checkbox is not being checked.

I have been debugging since a long time but couldn't identify the issue. Any suggestions about what could be wrong? Thank you.

Angular Version: 7.1

Nebular version: ^3.5.0

I think you should use it like in these examples
it works with value and checked inputs

<nb-checkbox [checked]="checked" (checkedChange)="toggle($event)">Toggle me</nb-checkbox>

i created stackblitz for you with working example https://stackblitz.com/edit/angular-nb-checkbox?file=src/app/app.component.ts

Add the following in your HTML:

<nb-checkbox status="primary" [value]="checked" (change)="setCheckedStatus($event)">Primary</nb-checkbox>

Add the following in your component.ts file:

checked: true; // declare this variable in your component
setCheckedStatus(checked) {
    console.log('checked', checked.target.checked);
    this.checked = checked.target.checked; // your variable
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM