Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { ModuleWithProviders, NgModule } from '@angular/core';
- import { CommonModule } from '@angular/common';
- import { Injectable, Inject } from '@angular/core';
- import * as WooCommerceAPI from 'woocommerce-api';
- //For exporting the service:
- //import { WooApiService } from './src/woocommerce.service';
- //export * from './src/woocommerce.service';
- @Injectable()
- export class WooApiService {
- woo: any;
- constructor(@Inject('config') private config: any) {
- this.woo = WooCommerceAPI(config);
- }
- fetchItems(itemType:string): Promise<any> {
- return new Promise((resolve, reject) => {
- this.woo.getAsync(itemType)
- .then((data:any) => resolve(JSON.parse(data.toJSON().body)))
- .catch((error:Error) => reject(error));
- });
- };
- }
- @NgModule({
- imports: [ CommonModule ],
- declarations: [],
- exports: []
- })
- export class WooApiModule {
- static forRoot(config: Object): ModuleWithProviders {
- return {
- ngModule: WooApiModule,
- providers: [ WooApiService, {provide: 'config', useValue: config}]
- };
- }
- }
Add Comment
Please, Sign In to add comment