Angular + httpService: POST & DELETE results?

Angular + httpService: POST & DELETE results?

本文关键字:DELETE results amp httpService POST Angular      更新时间:2023-09-26

我有一个角度服务,它应该做所有让我的控制器与我的API通信所需的http内容。

export interface IDummyEntityApiService {
    getAllDummies() : ng.IPromise<Array<Entities.IDummy>>;
}
class DummyEntityApiService implements IDummyEntityApiService {
    private http: ng.IHttpService;
    constructor($http : ng.IHttpService) {
        this.http = $http;
    }
    getAllDummies() {
        var url = "acme.com/api/dummies;
        return this.http.get(url).then(result => {
            return result.data;
        }, error => {
            // log error
        });
    }
}

然后我可以像这样使用:

dummyEntityApiService.getAllDummies.then(result => {
    // fill results into list
}, error => { 
    fancyToast.create("Ooops, something went wrong: " + error);
});

我现在的问题是 - 这将如何与POSTDELETE一起工作?我知道$httpService有像 .post(url, data).delete(url) 这样的方法,并且它们都返回IHttpPromise<{}>,但是将它们转换为IPromise并没有真正的意义,因为没有需要解决的数据?

实际上,你可以在 HTTP 请求完成后使用 promise 来执行某些东西。例如,您可以使用ng.IHttpPromise<any>