Search code examples
cordova-pluginsionic3

HTTP plugin is not installed error with ionic


$ ionic cordova plugin add cordova-plugin-http
$ npm install --save @ionic-native/http

The implementation is:

  constructor(private https: HTTP ) {
  }

  this.https.get('http://ionic.io', {}, {})
  .then(data => {
   this.httpData =data;
   console.log(data.status);
   })
   .catch(error => {

     console.log(error.status);

     });

And I get this error:

[20:49:03] console.warn: Native: tried calling HTTP.get, but the HTTP plugin is not installed. [20:49:03] console.warn: Install the HTTP plugin: 'ionic plugin add cordova-plugin-http'


Solution

  • If you do not want to modify the ionic-native plugin like suggested by @alpere or if the solution does not work you can always use the cordova plugin without ionic-native. To do so tell typescript that the http handle exists by adding the following somewhere below your imports:

    declare var http;
    

    And then use it like this:

    http.get(
      'https://ionic.io/',
      {},
      {},
      response => {
        console.log(response.status);
      },
      response => {
        console.error(response.error);
      },
    );
    

    Note that there is no need of this because cordova plugins are defined on a global scope. The downside of using plugins without the ionic-native wrapper is that you loose the nice type annotations, promise callbacks and in some cases you will have to trigger angular change-detection yourself.