2017-04-19 55 views
0

我是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,我无法找到正确的代码禁用/启用基于一个复选框选择选项。

回答

0

在复选框中使用[(ngModel)] =“user.check”,在select中使用[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> 
相关问题