![](/img/trans.png)
[英]how to get values from model function and pass the value on url in angular 6
[英]How to pass USER ID from template to function to get values in angular 5
當我單擊編輯時,我想將我的用戶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>
如果要在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 }
];
如果不知道路由,則可以檢查漫游: https ://angular.io/guide/router
下面會工作
<button mat-raised-button color="accent"
(click)="edit(visit?.ID)">EDIT</button>
在ts文件中,函數需要帶參數,也可以將arugment設為可選
edit(id?:any)
{}
您必須將id作為函數的參數傳遞:
<td><button mat-raised-button color="accent" (click)="edit(visit.ID)">EDIT</button></td>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.