I have web API method to get data from EmpID and I call this method from Angular 2 and want to bind data to form to update that.
I think I do not call web API method correctly from service, but it gives error that we cannot find this web API method.
Web API method:
[ Route("api/Employee/GetEdit/{id:int}") ]
public Employee GetEdit(int id) {
return db.Employees.Where(t => t.EmpID == id).FirstOrDefault();
}
Below is my service:
GetEdit(id:any) {
let headers = new Headers({ 'Content-Type': 'application/json', 'Accept': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.get('http://localhost:49221/Employee/GetEdit/' + id, headers)
.map((res: Response) => res.json());
//return this.http.get('http://localhost:49221/api/Employee')
// .map(this.extractData)
// .catch(this.handleError);
}
Below is my component class:
getEdit() {
this._service.GetEdit(1).subscribe(
posts => this.employee = posts,
error => console.error(error)
)};