【问题标题】:Adding ngIf condition for ngFor values为 ngFor 值添加 ngIf 条件
【发布时间】:2017-07-24 20:46:36
【问题描述】:

我有一个 ngFor,我将所有数据都带到这里。现在,如果状态为非活动状态,我需要隐藏一些按钮。我正在考虑为此使用ngIf。但我不知道如何为此编写条件。我如何检查状态是否处于非活动状态并为它们添加 NgIf 条件?

<tbody id="address-list"  *ngIf="addressData">
   <tr *ngFor="let full of addressData " class="{{full.status}}style show-{{full.status}}" data-target="#address-details-modal" data-toggle = "modal" (click)="seperateId(full.ID)">
   <td class="{{full.status}}style show-{{full.status}}"  >
      {{full.address1}} {{full.address2}}
   </td>
   <td class="{{full.status}}style show-{{full.status}}">
      {{full.type}}
   </td>
   <td class="{{full.status}}style show-{{full.status}}">
      {{full.status}}
   </td>
   </tr>
</tbody>

现在,如果状态为非活动状态。当我编辑那个。我应该隐藏编辑和删除按钮。

 <div class="modal-footer">
   <span class="action-btns" *ngIf="active">
   <button class="btn btn-primary btn-md edit-btn pull-left" title="Edits" id="edit-btn-address" (click)="editModal()"><span class="glyphicon glyphicon-pencil"></span></button>
   <button class="btn btn-danger btn-md delete-btn pull-left" title="Make Inactive" id="remove-btn-address" (click)="makeInactive()" ><span class="glyphicon glyphicon-trash" ></span></button>
   <button type="button" data-dismiss="modal" class="btn btn-default close-btn pull-right">Close</button>
   </span>
   <span class="edit-btns" *ngIf="edit" >
   <button type="button" class="btn btn-default cancel-btn" (click)="editm()">Cancel</button>
   <button type="button" data-dismiss="modal" class="btn btn-primary saveEqualBtn save-btn"    (click) = "TableUpdate(addressid.ID)" [disabled]="!addressHistory.form.valid" data-dismiss="modal">Save</button>
   </span>
   <span class="confirm-btns pull-left " *ngIf="inactive" >
   <span >Make Inactive?</span>
   <button type="button" class="btn btn-sm btn-default no-btn" (click)="makeInactive()" >No</button>
   <button type="button" class="btn btn-sm btn-danger yes-btn" data-dismiss="modal" (click)="AddressInactive(addressid.ID)" >Yes</button>
   </span>
</div>

为此,我需要一个 ngIf 值。所以点击这些将被隐藏。我怎么做??

【问题讨论】:

  • ngFor 中的对象是否具有非活动属性?
  • 是的。一些对象的状态是非活动的。因此,当我根据状态按钮单击它们时应该隐藏。
  • @RahulSingh 我没明白你要我做什么?我打开了链接。我应该登录吗?
  • 是的 prakash 请登录它的评论部分,我在其中使用这种东西
  • 我尝试用谷歌登录。但它没有登录。@RahulSingh

标签: angular angular-ng-if


【解决方案1】:

如果你有你想要的属性,你可以比较一下

<span class="confirm-btns pull-left " *ngIf="obj.property==='inactive'" >

【讨论】:

  • 我想添加ngIf = "inactive",然后使用ngIf 我想隐藏按钮。我需要知道。如何编写将ngIf 仅添加到非活动状态的条件。
  • 您不会只将 ngIf 添加到非活动状态,而是使用它来检查它是否处于非活动状态。您可以用 div 类围绕按钮并将 ng(如果存在)或直接放入按钮中。
猜你喜欢
  • 2021-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-23
  • 2019-12-08
  • 1970-01-01
  • 2018-03-21
  • 2017-12-10
相关资源
最近更新 更多