Angular2静态HTTP客户端

时间:2017-10-08 20:21:19

标签: angular angular-http angular2-http

出于某些原因,我想使用静态HTTP客户端服务。我尝试了如下,但我收到了一个错误。是否可以创建静态服务?

静态服务:

import { Http, URLSearchParams, Headers }  from '@angular/http';

export class ExampleService {
    static postSendTransaction(data, callback) {
        Http.post('https://xxxxxxxx', JSON.stringify(data), { // I got error here
            headers: new Headers({ 'Content-Type': 'application/json' })
        }).subscribe(
            response => {
                callback({data: response.json(), error: null});
            },
            error => {
                callback({data: null, error: error.statusText});
            }
        );
    }
}

示例电话:

ExampleService.postSendTransaction(this.data, postSendTransactionCallback);

我收到了这个错误:

  

属性'post'在类型'typeof Http'上不存在。

0 个答案:

没有答案