【发布时间】:2020-12-12 20:13:42
【问题描述】:
我的工作是完成以下功能。我有 3 个复选框,选择一个后,我希望另外两个也被选中。
我使用现成的组件来创建复选框。
<form [formGroup]="data" name="name" >
<div class="form-group">
<div class="form__element">
<nb-checkbox name="groupname" value="Check All" label="Check All" formControlName="isAgree" [(ngModel)]="myVar2" [ngModelOptions]="{standalone: true}"></nb-checkbox>
</div>
</div>
<div class="features__box">
<section class="agreements">
<ul class="features__list">
<li class="features__item" *ngFor="let agreement of data.agreements.value">
<div class="form__element">
<nb-checkbox name="groupname" value={{agreement.description}} label={{agreement.description}} [checked]="myVar2" (change)="myVar2 = !myVar2"></nb-checkbox>
</div>
</li>
</ul>
</section>
<section class="statements">
<ul class="features__list">
<li class="features__item" *ngFor="let statement of data.statements.value">
<div class="form__element">
<nb-checkbox name="groupname" value={{statement.description}} label={{statement.description}} [checked]="myVar2" (change)="myVar2 = !myVar2"></nb-checkbox>
</div>
</li>
</ul>
</section>
</div>
</form>
我在主复选框中添加了[(ngModel)] =" myVar2 "[ngModelOptions] =" {standalone: true} ",并添加了[checked] =" myVar2 "(change) =" myVar2 =! myVar2 to my next checkbox.
在file.component.ts 文件中我添加了myVar2: boolean = false;
但是,上述解决方案不起作用。我在控制台中收到以下错误
ERROR in src/app/file.component.html:64:66 - error NG8002: Can't bind to 'ngModelOptions' since
it isn't a known property of 'nb-checkbox'.
1. If 'nb-checkbox' is an Angular component and it has 'ngModelOptions' input, then verify that it is part of this module.
2. If 'nb-checkbox' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.
64 formControlName="isAgree" [(ngModel)]="myVar2" [ngModelOptions]="{standalone: true}"></nb-checkbox>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/app/file.component.ts:14:16
14 templateUrl: './file.component.html',
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component CeidgPositiveComponent.
src/app/file.component.html:94:121 - error NG8002: Can't bind to 'checked' since it isn't a known property of 'nb-checkbox'.
1. If 'nb-checkbox' is an Angular component and it has 'checked' input, then verify that it is part of this module.
2. If 'nb-checkbox' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.
94 <nb-checkbox name="groupname" value={{statement.description}} label={{statement.description}} [checked]="myVar2" (change)="myVar2 = !myVar2"></nb-checkbox>
~~~~~~~~~~~~~~~~~~
src/app/file.component.ts:14:16
14 templateUrl: './file.component.html',
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component File.
我已经导入了模块import {FormsModule, ReactiveFormsModule} from '@ angular / forms'; import {NgxsModule} from '@ ngxs / store';
有人知道如何解决这个问题吗?
【问题讨论】:
-
您需要导入
NbCheckboxModule