在Angular应用中,我有一个Job
对象和一个Offer
对象。
这是我的界面:
export interface IJob {
id: number;
title: string;
description: string;
employeeId?: number;
managerId: string;
imageUrl: string;
}
export interface IOffer {
id: number;
managerId: number;
jobId: number;
employeeId: number;
}
我正在显示所有作业详细信息,如下所示:
<table">
<thead>
<tr>
<th scope="col">Title</th>
<th scope="col">Description</th>
<th scope="col">Employee ID</th>
<th scope="col">Manager ID</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let job of jobs">
<td>{{ job.title }}</td>
<td>{{job.description}}</td>
<td>{{job.employeeId}}</td>
<td>{{job.managerId}}</td>
<td>
<button (click)="applyForJob(job)">Apply Now</button>
</td>
</tr>
</tbody>
</table>
我想使用此applyForJob(job)
方法为关联的作业创建Offer
对象。
目前,我的优惠服务中有这种方法,如果有帮助的话:
addOffer(offer: IOffer): Observable<IOffer> {
return this.httpClient.post<IOffer>(this.baseUrl, offer, {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
})
.pipe(catchError(this.handleError));
}
有人可以告诉我如何使用上述代码为特定工作创建职位吗?
答案 0 :(得分:1)
您可以执行以下操作。
applyForJob(job) {
let offer = new IOffer();
offer.id = job.id; // use unique id for this
offer.managerId = job.managerId;
offer.jobId = job.id;
offer.employeeId = job.employeeId;
myOfficeService.addOffer(offer).subscribe((res: any) => {
console.log(res);
});
}