【发布时间】:2018-11-10 18:02:00
【问题描述】:
我有这项服务,我需要将产品返回到我在这里不使用的组件 HttpClient 或 Observable 因为我不需要它们
export class StoreDataProvider {
private _wooData: any;
constructor() {
this._wooData = Woo({
url: 'http://example.com/',
consumerKey: 'key here',
consumerSecret: 'key here',
wpAPI: true,
version: 'wc/v3'
});
}
getAllProducts() {
return this._wooData.get('products', (err, data, res) => {
return res
});
}
}
上面的代码返回标头,而不是产品,但是如果我在服务本身中控制产品而不是返回,我会得到产品!代码是这样的:
export class StoreDataProvider {
private _wooData: any;
constructor() {
this._wooData = Woo({
url: 'http://example.com/',
consumerKey: 'key here',
consumerSecret: 'key here',
wpAPI: true,
version: 'wc/v3'
});
}
getAllProducts() {
this._wooData.get('products', (err, data, res) => {
console.log(res);
});
}
}
如果我在服务中进行控制台登录,则组件中的代码只是 console.log( this._wooService.getAllProducts() )
那么我在这里错过了什么?
【问题讨论】:
-
我不太确定你在问什么,但答案可能是stackoverflow.com/q/6847697/3001761
-
我在问如何从不是来自 HttpClient 模块的服务返回响应! @SiddAjmera 帮助了我!并且我批准了他的回答,您可以查看一下无论如何感谢您的光临并且很有趣地帮助我解决了我的问题! ♥
标签: javascript angular ionic3 angular-services