我在组件html文件中有此表:
<table class="table table-hover table-responsive table-condensed">
<thead>
<tr>
<th>Image</th>
<th>Form ID</th>
<th>Text Input One</th>
<th>Text Input Two</th>
<th>Owner</th>
<th>Date Submitted</th>
<th>Date Edited</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody *ngFor="let form of fetchedForms">
<tr>
<td class="img-resized"><img class="img-thumbnail img-responsive" src="./uploadsFolder/{{form.owner}}/{{form.imagePath}}"></td>
<td>{{form._id}}</td>
<td>{{form.textInputOne}}</td>
<td>{{form.textInputTwo}}</td>
<td>{{form.owner}}</td>
<td>{{form.dateSubmitted | date: 'medium'}}</td>
<td>{{form.updatedAt | date: 'medium'}}</td>
<td>
<button class="btn-default" [routerLink]="['edit', form._id]"><i class="fa fa-pencil"></i></button>
</td>
<td>
<button class="btn-danger" (click)="onDelete(form._id)"><i class="fa fa-trash"></i></button>
</td>
</tr>
</tbody>
现在,细胞
<td>{{form.updatedAt | date: 'medium'}}</td>
总是显示,我想使用某些条件来隐藏/显示它,例如:
*ngIf="form.dateSubmitted != form.updatedAt"
所以我想使用的代码是:
<td *ngIf="form.dateSubmitted != form.updatedAt">{{form.updatedAt | date: 'medium'}}</td>
但这就是它的呈现方式:
如果* ngIf返回true(如图所示),以便表格可以正确对齐/显示,我如何添加一个空单元格?
这是文件的仓库:https : //github.com/predatorkill/ng2-forms-demo/tree/master/src/app/client/userForms/formsTable
您需要隐藏单元格的内容,而不是隐藏整个单元格。span
例如,使用inner :
<td>
<span *ngIf="form.dateSubmitted != form.updatedAt">{{form.updatedAt | date: 'medium'}}</span>
</td>
通过这种方法,td
始终可见(因此您不会看到残破的表),但是如果需要的话,其内容为空。
..,然后将*ngFor
循环放在<tr>
元素上,而不是上<tbody>
。喜欢:
<tbody>
<tr *ngFor="let form of fetchedForms">
...
(在Angular中,*ngFor
迭代分配的元素,而您只想单个tbody
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句