错误TS2339:属性'诊断'类型' CordovaPlugins'

时间:2016-09-28 06:53:37

标签: cordova angular ionic2

我正在使用Ionic 2。

我关注了this,并执行了以下操作:

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);
      });
    }
  }

我收到以下错误:

  

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

我注意到window.cordovaundefined

如果有人可以建议我如何使用Cordova插件,我将不胜感激。

由于

1 个答案:

答案 0 :(得分:0)

因此,对于Ionic 2,请尝试使用window [' plugins']代替cordova.plugins。