0

I tried a code in my project in Ionic 2 but i have this error.

ApiAIPlugin is not defined

I added:

declare const ApiAIPlugin: any;

In my code. I also added:

public ApiAIPlugin: ApiAIPlugin

In my constructor and nothing changed. I still have the same error.

How do I solve it?

import { Component,NgZone } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Platform } from "ionic-angular";

//declare var window:any;
declare var ApiAIPromises:any;
//declare const ApiAIPlugin: any;
@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  answer:String;
  constructor(public navCtrl: NavController,public platform: Platform, public ngZone: NgZone) {
    //ai
    /*platform.ready().then(() => {
      ApiAIPromises.init({
        clientAccessToken: "mytoken"
      })
      .then((result) =>  console.log(result))

    });
*/
platform.ready().then(() => {
  ApiAIPromises.init({
    clientAccessToken: "4596e9d3a1b641db86d96a0ae86e165f"
  })
  .then((result) =>  console.log(result))

});


    //ai
  }
  ask(question) {
    ApiAIPromises.requestText({
      query: question
    })
    .then(({result: {fulfillment: {speech}}}) => {
       this.ngZone.run(()=> {
         this.answer = speech;
       });
    })
  }

}
Malav Shah
  • 3
  • 1
  • 3

0 Answers0