2017-09-29 82 views
0

我在Angular中有一個彈出窗口,它用於刪除確認。如何將對象傳遞給彈出窗口<div>對象範圍如何在指令外角度工作

示例代碼:

<tr *ngFor="let **user** of users"> 
    <td style="text-align: -webkit-center;"> 
     <button (click)="showDeleteConfirm()"> 
     <span class="glyphicon glyphicon-trash"></span>Delete 
     </button> 
    </td> 
</tr> 

需要上述用戶在這裏通過:

<div class="popupDelete"> 
    <popup #popupDelete (confirmClick)="ConfirmDelete(**user**)"> 
     Are you sure, you want to delete this user? 
     <br> 
    </popup> 
</div> 

回答

0

由於您的popupDelete是不是你tr你需要使用一個孩子控制器爲此。

在HTML中,注意參數showDeleteConfirmConfirmDelete缺少參數:

<tr *ngFor="let user of users"> 
    <td style="text-align: -webkit-center;"> 
       <button (click)="showDeleteConfirm(user)"> 
       <span class="glyphicon glyphicon-trash"></span>Delete 
      </button> 
      </td> 
</tr> 

<div class="popupDelete"> 
    <popup #popupDelete (confirmClick)="ConfirmDelete()"> 
     Are you sure, you want to delete this user? 
     <br> 
    </popup> 

</div> 

在您的TS:

public showDeleteConfirm(user) 
{ 
    this.userToDelete = user; 
    ... 
} 

public ConfirmDelete() 
{ 
    Database.Delete.This.User(this.userToDelete); 
} 

如果您popupDelete是你tr的孩子,你可以通過ConfirmDelete與您的*ngFor介紹的user相同。不過,你最終會得到多個popupDelete

+1

謝謝...... !!!它解決了。 :-) – Tinku