问题
I'm trying to use WooCommerce API in Ionic4 application after importing API in my home page I cannot see anything on output screen below is code:
home.page.ts
import { Component } from '@angular/core';
import * as WC from '@woocommerce/woocommerce-rest-api';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
//Local Objet WooCommerce of type any
WooCommerce: any;
constructor() {
this.WooCommerce = WC({
url: "https://shop.example.com",
consumerKey: "ck_fc057c56e5b430c9f4be64c86225e11943647ca1",
consumerSecret: "cs_12842c6e3c1122e9a17cb5c6b4e33aca3e0199528",
});
this.WooCommerce.getAsync("products").then( (data) => {
console.log(data);
}, (err) => {
console.log(err)
})
}
}
using this new WooCommerce API, and when I import this API my home page of Ionic app disappears. and when I comment this code it again reappears. Here is how I'm importing and using it. after running this code I'm getting this on console Output:
https://prntscr.com/p8kbmy
回答1:
Based on your screenshot, you are having problems with global
not being defined.
The solution seems to be to define global yourself using this line:
(window as any).global = window;
Open /src/polyfills.ts
and add this to the bottom:
// BUG FIX: Add global to window, assigning the value of window itself.
// https://github.com/socketio/socket.io-client/issues/1166#issuecomment-386195105
(window as any).global = window;
来源:https://stackoverflow.com/questions/58039777/getting-blank-screen-after-importing-and-using-woocommerce-api