这是我从服务中调用的未执行的方法
addData(data) {
let _body = JSON.stringify(data);
let headers = new Headers({'Content-Type': 'application/json;charset=utf-8'});
let url = 'http://localhost:8080/obj/addData';
let requestoptions:RequestOptions = new RequestOptions({
method: RequestMethod.Post,
url: url,
headers: headers,
body : _body
});
console.log("test");
return this._http.request(new Request(requestoptions))
.map((res:Response) => {
console.log(res);
return res.json();
});
}
我添加了console.log来验证是否调用了该方法,因为尽管我调用了一个方法却没有做任何事情
因为该request
方法不会单独执行。鉴于您已经订阅了该addData
方法,建议您改用这种post
方法:
addData(data) {
let _body = JSON.stringify(data);
let headers = new Headers({'Content-Type': 'application/json;charset=utf-8'});
let url = 'http://localhost:8080/obj/addData';
console.log("test");
return this._http.post(url, _body, { headers })
.map((res:Response) => {
console.log(res);
return res.json();
});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句