2017-09-03 53 views
-1

我有角4材料表格單元格中的按鈕,我想只出現在時錶行懸停:設置按鈕出現在懸停

<md-cell *cdkCellDef="let row" contenteditable='false' > 
     <div *ngIf="!row.editorEnabled" >{{row.goalStatusName}} 
      <button md-icon-button><md-icon (click)="row.editorEnabled=true;" mdTooltip="Edit">mode_edit</md-icon></button> 
      </div> 
</md-cell> 

如何實現這一目標?

更新: 整個代碼:

<md-cell *cdkCellDef="let row" contenteditable='false' > 
     <div *ngIf="!row.editorEnabled" >{{row.goalStatusName}} 
      <button md-icon-button><md-icon (click)="row.editorEnabled=true;" class="editButton" mdTooltip="Edit">mode_edit</md-icon></button> 
      </div> 
     <div *ngIf="row.editorEnabled" > 
      <md-input-container><input mdInput [(ngModel)]="row.goalStatusName" #goalName></md-input-container> 
      <button md-icon-button> 
       <md-icon (click)="modifyGoal(row.goalStatusId,row.goalStatusName)" mdTooltip="Save" style="color:green;font:bold;" >done</md-icon> 
      </button> 
      <button md-icon-button> 
       <md-icon (click)="row.editorEnabled=false" mdTooltip="Cancel" style="color:red;font:bold;" >clear</md-icon> 
      </button> 
      </div> 
    </md-cell> 

回答

2
button{ display:none} 
md-cell:hover{ 

    button{ 
    display:block 
    } 
} 
+0

謝謝。另外,如何在按鈕點擊時將焦點引入md-cell中的另一個輸入元素? – HBK

+0

把一個#elem放在輸入上,然後(click)=「row.editorEnabled = true; elem.focus()」 – Milad

+0

我使用* ngFor和所有輸入元素會有相同的id然後 – HBK

1
.editButton{ visibility: hidden} 
md-cell:hover .editButton{ 
visibility: visible; 
} 

這個工作!