1
因此,我有以下代碼顯示在主頁上的表,我有兩個按鈕表中的每一行,「編輯」和「刪除」。所以當我點擊編輯按鈕時,模式被打開。現在我的問題是,我需要將按鈕點擊某個員工的「員工ID」傳遞給該員工。我怎樣才能做到這一點?所以我們可以說我有一個empoyee ID:「101」並且想要編輯信息,如何將這個「101」傳遞給編輯模式組件在按鈕上點擊,這樣我就可以在文本框中填入該員工的退職我的模式?如何將數據從一個組件發送到另一個組件按鈕單擊角度2
@Component({
selector: 'ops-employee',
pipes: [],
styles: [],
template: `
<ops-addmodal [(open)]="addEmployeeOpen" (check)="updateEmployeeList($event)"></ops-addmodal>
<ops-editmodal [(open)]="editEmployeeOpen" [data]="editId" (check)="editEmployeeList($event)">
</ops-editmodal>
<div class="col-md-8 col-md-offset-2">
<h1> Employee Info </h1>
<hr>
<button class="btn btn-lg btn-primary" (click)="addEmployee()">Add</button>
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Role</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr *ngFor = "#employee of employeeDetails">
<td>{{employee.empName}}</td>
<td>{{employee.empAge}}</td>
<td>{{employee.empRole}}</td>
<td>
<button class="btn btn-sm btn-default" (click)="editEmployee(employee.empId)">Edit</button>
<button class="btn btn-sm btn-danger" (click)="deleteEmployee(employee.empId)">Delete</button>
</td>
</tr>
</tbody>
</table>
</div>
`,
directives: [AddEmployeeModalComponent, EditEmployeeModalComponent, ModalComponent]
})
非常感謝!好主意......我試圖用@ViewChild來思考,但感到困惑。 – Kashyap