简体   繁体   English

角度2客户端条件

[英]angular 2 client side condition

I am trying to call api on block/unblock Icon button to block and unblock user. 我试图在“阻止/取消阻止图标”按钮上调用api以阻止和取消阻止用户。 Now I want to ask how could I change Icon Image if user active to show unlock image in front of active and vice versa. 现在,我想问一下,如果用户处于活动状态以在活动对象前面显示解锁图像,反之亦然,该如何更改图标图像。

Image 图片

在此处输入图片说明

Html HTML

 <link href="../../font-awesome-4.6.3/css/font-awesome.min.css" rel="stylesheet" /> <h1>User View </h1> <div class="row"> <div class="panel panel-default"> <div class="table-responsive"> <table class="table table-striped table-bordered"> <thead> <tr> <th class="text-center">First Name</th> <th class="text-center">Last Name</th> <th class="text-center">Email</th> <th class="text-center">Status</th> <th class="text-center">Block/Unblock</th> </tr> </thead> <tbody> <tr *ngFor="let user of _data | paginate: { itemsPerPage: 10, currentPage: p }"> <th>{{user.FirstName}}</th> <th>{{user.LastName}}</th> <th>{{user.Email}}</th> <th>{{ user.IsActive == true ? 'Active' : 'Block' }}</th> <th> <div class="text-center"> <button type="button" class="btn btn-xs " (click)="approvalPendingRequest(user.SubscriptionId)"> <i class="fa fa-unlock" aria-hidden="true"></i> </button> </div> </th> </tr> </tbody> </table> <pagination-controls (pageChange)="p = $event" #api></pagination-controls> </div> </div> </div> 

Quickfix 快速解决

Change class="fa fa-unlock" to class="fa {{ user.IsActive == true ? 'fa-lock' : 'fa-unlock' }}" class="fa fa-unlock"更改为class="fa {{ user.IsActive == true ? 'fa-lock' : 'fa-unlock' }}"

You can use ngClass to accomplish that: 您可以使用ngClass来实现:

<button type="button" class="btn btn-xs " (click)="approvalPendingRequest(user.SubscriptionId)">
    <i [ngClass]="['fa', user.IsActive ? 'fa-lock' : 'fa-unlock']" aria-hidden="true"></i>
</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM