如何将值索引或 id 传递给 EditDetail() 参数。一旦我单击 html 中的 onEditDetail(),我希望它被放在 onEditDetail() 的括号内
ngOnInit() {
this.route.params
.subscribe((params: Params) => {
this.id = +params['id'];
this.user = this.userService.getUser(this.id);
});
}
onEditDetail(id: string) {
console.log(id);
}
user-detail.component.html
<div class="container">
<div class = "row">
<div class="col-md-3"></div>
<div class = "col-md-8">
<div class="card">
<div class="card-header">
{{ user.l_name}} 's Complete Information<span class="pull-right"><input class="form-control" placeholder="Search User" name="srch-term" id="srch-term" type="text"></span>
</div>
<table class="table table-responsive">
<thead class="thead-default">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Contact Number</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ user.f_name }}</td>
<td>{{ user.l_name }}</td>
<td>{{ user.contact_no }}</td>
<td><button class=" btn btn-primary" style="cursor: pointer;" (click)="onEditDetail()">Edit</button> </td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>