2017-04-25 69 views
0

2顯示隱藏我想基於索引Angularjs基於索引

template

<tbody> 
     <tr *ngFor="#item of itemList; #i = index"> 
     <td class="text-center">{{i+1}}</td> 
     <td class="text-center">{{item.name}}</td> 
     <td class="text-center">{{item.email}}</td> 
     <td class="text-center">{{item.city}}</td> 
     <td class="text-center"><span (click)="removeItem($index)" class="glyphicon glyphicon-remove"></span> 
     <span class="glyphicon glyphicon-plus" (click)="onSelect(i)"></span> 
     <td [hidden]="IsHidden">{{item.orderid}}</td> 
     </tr> 

.ts

IsHidden= true; 
    onSelect(index){ 
    console.log(this.itemList[index]); 
    this.IsHidden = !this.IsHidden; 
    } 

顯示隱藏DIV當過我點擊一日一它全部顯示tr hidden字段。

我該如何解決這個問題?

回答

0

因爲你需要使用的item.isHidden代替this.isHidden

<tbody> 
    <tr *ngFor="#item of itemList; #i = index"> 
    <td class="text-center">{{i+1}}</td> 
    <td class="text-center">{{item.name}}</td> 
    <td class="text-center">{{item.email}}</td> 
    <td class="text-center">{{item.city}}</td> 
    <td class="text-center"><span (click)="removeItem($index)" class="glyphicon glyphicon-remove"></span> 
    <span class="glyphicon glyphicon-plus" (click)="onSelect(item)"></span> 
    <td [hidden]="item.isHidden">{{item.orderid}}</td> 
    </tr> 

TS

onSelect(item){ 
    console.log(this.itemList[index]); 
    item.IsHidden = !item.IsHidden; 
} 
+0

沒有它不工作 –

+0

隱藏顯示沒有工作,現在總是顯示 –

+0

雅它的工作怎麼只有一個顯示在時間 –