单击复选框时启用选择选项

时间:2017-04-19 08:10:05

标签: angular angular2-forms

我是angular2的新手。我只需在单击复选框时启用选择选项。

形式:

<tr *ngFor="let user of users">
   <td>{{ user.id }}</td>
   <td><input type="checkbox" name="switch" (click)="toggleSwitch(user.id, $event)"></td>
   <td>
       <select id="intensity" (change)="toggleOption(user.id, $event)" [disabled]="butDisabled">
           <option *ngFor="let int of intensity" [value]="int" >{{int}}</option>
       </select>
   </td>
</tr>

组件:

export class UsersComponent {
    butDisabled: boolean = true;
}

正如我所说,我是角色2的新手,我无法根据复选框找到正确的代码来禁用/启用选择选项。

1 个答案:

答案 0 :(得分:0)

在复选框中使用[(ngModel)] =“user.check”并选择[disabled] =“!user.check”解决问题。

其他用户回答了这个问题,但不幸的是用户已删除了答案

<tr *ngFor="let user of users">
     <td>{{ user.id }}</td>
      <td><input type="checkbox" name="switch" [(ngModel)]="user.check"
               (click)="toggleSwitch(user.id, $event)">
      </td>
      <td>
         <select id="intensity" (change)="toggleOption(user.id, $event)" [disabled]="!user.check">
             <option *ngFor="let int of intensity" [value]="int" >{{int}}</option>
         </select>
      </td>
</tr>