Ionic WooCommerce - 不能将命名空间'WooCommerceProvider'用作类型

时间:2018-04-23 19:22:55

标签: wordpress ionic-framework woocommerce ionic3 woocommerce-rest-api

我正在尝试使用WooCommerce API为我的Ionic APP检索产品列表,并且我已经为此创建了一个提供程序,其中包含以下代码:

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;
});
}
}

我用自己的密钥取代了消费者密钥和秘密。以下是我尝试接收产品列表的页面:

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;
      });

  }

我收到以下错误:[ts]无法使用名称空间'WooCommerceProvider'作为类型。

1 个答案:

答案 0 :(得分:1)

导入import { WooCommerceProvider } from '../providers/woo-commerce/woo-commerce';导入命名空间而不是具体的提供者。

查看类型文件,提供者的名称是什么。