2017-04-19 45 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> 
相關問題