简体   繁体   English

无法点击星云主题angular的nb-checkbox

[英]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 HTML

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

TypeScript TypeScript

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

Module.ts模块.ts

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

imports: [NbCheckboxModule]

toggle function is being called fine but checkbox is not being checked.切换 function 被正常调用,但未选中复选框。

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 Angular 版本:7.1

Nebular version: ^3.5.0星云版本:^3.5.0

I think you should use it like in these examples我认为您应该像在这些示例中一样使用它
it works with value and checked inputs它适用于valuechecked输入

<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我使用工作示例https://stackblitz.com/edit/angular-nb-checkbox?file=src/app/app.component.ts 为您创建了 stackblitz

Add the following in your HTML:在 HTML 中添加以下内容:

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

Add the following in your component.ts file:在您的 component.ts 文件中添加以下内容:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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