error TS2339: Property 'diagnostic' does n

2019-03-05 12:58发布

I am using Ionic 2.

I followed this, and did the following:

cordova plugin add cordova.plugins.diagnostic
npm install -g typings 
typings install dt~cordova --save --global

app.ts

    if (window.cordova && cordova.plugins) {
      cordova.plugins.diagnostic.isLocationEnabled(function (enabled) {
        alert("Location is " + (enabled ? "enabled" : "disabled"));
      }, function (error) {
        alert("The following error occurred: " + error);
      });
    }
  }

I get the following error:

error TS2339: Property 'diagnostic' does not exist on type 'CordovaPlugins'.

I notice that window.cordova is undefined.

If anyone can advise how I can get the Cordova Plugin working, I would appreciate it.

Thanks

1条回答
淡お忘
2楼-- · 2019-03-05 13:18

So for Ionic 2, try window['plugins'] in place of cordova.plugins.

查看更多
登录 后发表回答