Dwight Lisper Dwight Lisper - 4 years ago 329
TypeScript Question

Typescript with Api.AI in Ionic 2

I'm having a trouble of importing my ApiAIPlugin inside Ionic 2 Angular 2 with Typescript app

I have added the plugin via ionic plugin add cordova-plugin-apiai comamnd it's inside config.xml:

<plugin name="cordova-plugin-apiai" spec="~1.7.4"/>


but I don't know how to import it inside my home.ts file,
I have tried adding

declare var window: any


above my @Component({})
and trying to use it inside constructor like this:

window.plugins.ApiAIPlugin.init({...})


but both in the browser and in the emulator I get:
Cannot read property 'ApiAIPlugin' of undefined...

can someone help me?

p.s. used this link to try the above mentioned things

Answer Source

ApiAIPlugin is your global object for the plugin. You should declare the global object directly.

declare var ApiAIPlugin:any;

and use

ApiAIPlugin.init({...})

Or try

 declare var window:any;

and:

window.ApiAIPlugin.init({})
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download