Cannot use namespace 'WooCommerceProvider' as a type


#1

I’m trying to use the WooCommerce API to retrieve a list of products for my Ionic APP, and I’ve created a provider for that purpose, which contains the following code:

import { Injectable } from '@angular/core';
import * as WC from 'woocommerce-api';

@Injectable()
export class WooCommerceProvider {
  Woocommerce: any;
  WoocommerceV2 : any;
  constructor() {

this.Woocommerce =  WC({
  url: 'https://colorvet.ro/wp-json/wc/v1/products',
  consumerKey: 'xxxxxxxxxxxxxxxx',
  consumerSecret: 'xxxxxxxxxxxxx',
  wpAPI: true, // Enable the WP REST API integration
  queryStringAuth: true,
  verifySsl: true,
  version: 'wc/v2' // WooCommerce WP REST API version
});




}
  init(){
    return new Promise((resolve, reject) => {
      this.Woocommerce;
});
}
}

I’ve replaced the consumer key and secret with my own. The following is the page where I try to receive the list of products:

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, AlertController } from 'ionic-angular';
import * as WC from 'woocommerce-api';
import { WooCommerceProvider } from '../providers/woo-commerce/woo-commerce';

/**
 * Generated class for the ShopPage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-shop',
  templateUrl: 'shop.html',
})
export class ShopPage {

  produse: any[];
  WooCommerce: any;

  constructor(public navCtrl: NavController, public navParams: NavParams, 
     private alertCtrl: AlertController,private wooProvider: WooCommerceProvider ) {

      this.WooCommerce = wooProvider.WooCommerce;

      this.WooCommerce.getAsync("products").then((searchData) => {
        this.produse = JSON.parse(searchData.body).products;
      });

  }

I get the following error : [ts] Cannot use namespace ‘WooCommerceProvider’ as a type.


#2

Have you tried using ng2woo? That’s the direction I would go – either using someone else’s Angular wrapper, or writing my own.


#3

Thanks for the tip. I did exactly as the Readme said, and I keep getting the following error:

"No route was found matching the URL and request method"

#4

When are you getting the error, and what is its stack trace?


#5

I get the error after I run Ionic Serve and enter the page where I should receive the products from the WooCommerce API. This is the message I get in the debugger: