I am creating a service
in angular
that consumes a package to query a api
, but I always get the same error;
Can not resolve all parameters for ApiService: (?).
o Code:
import { Injectable, Inject } from '@angular/core';
import { WooCommerceAPI } from 'woocommerce-api';
@Injectable()
export class ApiService {
woocommerce: any;
constructor(@Inject(WooCommerceAPI) woocommerce: WooCommerceAPI) {
this.woocommerce = woocommerce({
url: 'http://wc-project.dev/',
consumerKey: 'ck_123',
consumerSecret: 'cs_123',
wpAPI: true,
version: 'wc/v2'
});
}
getProducts(): any {
return this.woocommerce.get('products');
}
}
I've tried using OnInit
but I get the error
this.woocommerce is undefined
Because the ngOnInit
function is started even before the attribute declaration until I understand this error.
But how can I use the api package in my service
?