【发布时间】:2017-11-02 02:42:42
【问题描述】:
我有一个通过单击按钮显示/隐藏元素的组件。
这是我的html
<div *ngFor="let history of histories | sortdate: '-dateModified'">
<p><b>{{ history.remarks }}</b> - <i>{{history.dateModified | date:'short'}}</i></p>
<a href="google.com"
[class.datatable-icon-right]="history.$$expanded"
[class.datatable-icon-down]="!history.$$expanded"
title="Expand/Collapse Row"
(click)="toggleExpandRow(history)"></a>
<!-- hide/show this by clicking the button above.-->
<div *ngFor="let step of history.steps; let i = index">
<b>{{i+1}}.</b> {{step}}
<span class="clear"></span>
</div>
<hr />
</div>
还有我的.ts
toggleExpandRow(row) {
console.log('Toggled Expand Row!', row);
//row
return false;
}
尝试搜索,但找不到任何相同的样本。
在 jquery 上,我可以做到这一点,但在 Angular2 上,我很难做到这一点。
【问题讨论】:
-
你想隐藏哪个元素?使用 ngIf 指令
-
我想显示/隐藏这个
<div [hidden]="!history.$$expanded" *ngFor="let step of history.steps; let i = index"> -
将其包装在
<ng-container ngIf="shown">...中,将shown属性添加到组件并在toggleExpandRow中切换它 -
可能是你从这个堆栈答案中得到你的答案:stackoverflow.com/questions/35163009/…
-
但是,它是关于按行显示/隐藏。不隐藏/显示所有数据。