簡體   English   中英

角度2客戶端條件

[英]angular 2 client side condition

我試圖在“阻止/取消阻止圖標”按鈕上調用api以阻止和取消阻止用戶。 現在,我想問一下,如果用戶處於活動狀態以在活動對象前面顯示解鎖圖像,反之亦然,該如何更改圖標圖像。

圖片

在此處輸入圖片說明

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> 

快速解決

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

您可以使用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