【发布时间】:2016-10-13 14:09:03
【问题描述】:
我在带有来自引导程序的图标的标题表中显示箭头,问题是当我点击一列时,所有列都得到图标类这里是在谈论什么:
这是代码:
HTML ->
<table class="table table-hover">
<thead>
<th (click)="orderBy('username')">Username<span [ngClass]="displayArrow()"></span></th>
<th (click)="orderBy('email')">Email<span [ngClass]="displayArrow()"></span></th>
<th (click)="orderBy('id')">Id<span [ngClass]="displayArrow()"></span></th>
<th (click)="orderBy('roleId')">Role Id<span [ngClass]="displayArrow()"></span></th>
</thead>
<tbody>
<tr *ngFor="let user of usersListData | orderByController: OrderByParams">
<td (click)="onSelectFilterParam(user.username)">{{user.username}}</td>
<td (click)="onSelectFilterParam(user.email)">{{user.email}}</td>
<td (click)="onSelectFilterParam(user.id)">{{user.id}}</td>
<td (click)="onSelectFilterParam(user.roleId)">{{user.roleId}}</td>
</tr>
</tbody>
应用组件->
private toggleArrow = 0;
orderBy(columnName: string) {
this.toggleArrow++;
if(this.toggleArrow > 2) {
this.toggleArrow = 0;
}
console.log(this.toggleArrow);
}
displayArrow() {
if(this.toggleArrow === 0) {
return '';
}
else if(this.toggleArrow === 1) {
return 'glyphicon glyphicon-chevron-up';
}
else if(this.toggleArrow === 2) {
return 'glyphicon glyphicon-chevron-down';
}
}
可以只将类绑定到一个元素吗?
【问题讨论】:
-
可以。你最后想要什么?告诉我们。
-
我希望箭头只显示在点击的列中,而不是像上图那样。
标签: twitter-bootstrap angular typescript binding