私はEmpIDからデータを取得するWeb APIメソッドを持っています。このメソッドをAngular 2と呼び、フォームにデータをバインドして更新します。Angular 2 Web APIを使用してIDからデータを取得
サービスから正しくWeb APIメソッドを呼び出さないと思いますが、このWeb APIメソッドが見つからないというエラーが表示されます。
ウェブAPI方法:以下
[ Route("api/Employee/GetEdit/{id:int}") ]
public Employee GetEdit(int id) {
return db.Employees.Where(t => t.EmpID == id).FirstOrDefault();
}
私のサービスです。
以下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);
}
私のコンポーネントクラスです:
getEdit() {
this._service.GetEdit(1).subscribe(
posts => this.employee = posts,
error => console.error(error)
)};
クロスオリジンリクエストエラーが発生した場合は、ブラウザの[ネットワーク]タブを確認してください。 – Malwaregeek
@Malwaregeek、はいクロスソースネットワークエラーが発生しました。 – Hitesh