【发布时间】:2017-05-04 08:56:12
【问题描述】:
我正在尝试在 Angular 2 中创建 Delete 请求。
我所做的是这样的-
import { Component } from '@angular/core';
import { Http, RequestOptions, URLSearchParams } from '@angular/http';
//import { Http, Response, Headers, RequestOptions, URLSearchParams } from '@angular/http';
import { Profile } from '../../dataModel/Profile.ts'; //Data Model
@Component({
selector: 'profile-list',
template: require('./profileList.component.html'),
styles: [require('./profileList.component.css')]
})
export class ProfileListComponent
{
private _deleteProfileUrl: string = "/api/Profile/Delete";
constructor(private http: Http)
{
}
public deleteProfile(profileId)
{
this.http.delete(this._deleteProfileUrl, new RequestOptions({
// Have to make a URLSearchParams with a query string
search: new URLSearchParams('profileId=' + profileId) // <-----
}));
alert("Deleted - " + profileId);
}
}
所以,我正在创建一个这样的删除请求-
this.http.delete(this._deleteProfileUrl, new RequestOptions({
// Have to make a URLSearchParams with a query string
search: new URLSearchParams('profileId=' + profileId) // <-----
}));
但它不工作并且没有给出任何错误。
因为如果调用了deleteProfile函数,只有alert来了,而没有做任何AJAX请求。
因为在调用函数后我有这样的事情-
我保证 API 运行良好。
那么,谁能帮我解决我做错了什么?
此外-
我的完整代码可以在here (if needed)找到。
提前感谢您的帮助。
【问题讨论】:
标签: javascript angular angular2-forms angular2-services