繁体   English   中英

如何选择所有复选框,但不选择特定复选框?

[英]How to select all checkboxes but unselect a particular checkbox?

我创建一个复选框列表并创建另一个复选框,当我单击该复选框时,所有列出的复选框都被选中,但是当我取消选中一个复选框时,所有复选框都未被选中。 这是我的代码:

    <input type="checkbox" class="custom-control-input" (change)="inviteAll()" [(ngModel)]="checked">
    <ul>
    <li class="peopleselectlist-item" *ngFor="let connection of connections">
        <img *ngIf="connection.imageUrl === '' || connection.imageUrl === null" src="assets/images/default_user.png" alt="" class="connection-img">
        <img *ngIf="connection.imageUrl !== '' && connection.imageUrl !== null" src="{{connection.imageUrl}}" alt="" class="connection-img">
         <h5>{{connection.firstName}}</h5>
         <label class="custom-control custom-checkbox">
  <input type="checkbox" class="custom-control-input" value="{{connection.userId}}" (change)="tagUser(connection.userId)" [(ngModel)]="checked">
  <span class="custom-control-indicator"></span></label> </li> <ul>

如何解决这个问题呢。 当我选择一个checkox时,仅取消选中该复选框。

尝试添加索引值以确保唯一性。 像这样:

*ngFor="let connection of connections;let i = index"

并将[(ngModel)]="checked"更改为[(ngModel)]="checked[i]"并在ts / js文件中创建checked数组。 另外,请尝试在复选框字段中id={{i}}

暂无
暂无

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

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