我想在点击编辑时将我的用户ID传递给服务。
<tr *ngFor="let visit of visits" style="border-top: 1px solid black">
<td>{{ visit?.ID }}</td>
<td>{{ visit?.username }}</td>
<td>{{ visit?.height }}</td>
<td>{{ visit?.weight }}</td>
<td>{{ visit?.patientnote }}</td>
<td>{{ visit?.doctornote }}</td>
<td>{{ visit?.nursenote }}</td>
<td><button mat-raised-button color="accent" (click)="edit()">EDIT</button></td>
<td><button mat-raised-button color="warn" (click)="delete()">DEL</button></td>
答案 0 :(得分:2)
如果你想在url中传递值,你必须使用Angular Routing,如下所示
import {Component} from '@angular/core';
import {Component} from '../Module/Component';
import {ListComponent} from "../Module/ListComponent";
export const ApplicationRoutes = [
{ path: 'Rpt/:id', component: Component },//allows to pass id in route
{ path: 'RptList', component: ListComponent },
{ path: '', component:ListComponent }
];
如果不了解路由,您可以检查rounting:https://angular.io/guide/router
下面的将起作用
<button mat-raised-button color="accent"
(click)="edit(visit?.ID)">EDIT</button>
在ts文件函数中需要带参数,你可以使arugment可选
edit(id?:any)
{}
答案 1 :(得分:0)
你必须传递id作为函数的参数:
<td><button mat-raised-button color="accent" (click)="edit(visit.ID)">EDIT</button></td>