Ionic 2:使用Cordova插件 [英] Ionic 2: Using Cordova Plugins

查看:179
本文介绍了Ionic 2:使用Cordova插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了很多谷歌搜索,似乎无法得到很多答案,在Ionic 2中调用Cordova插件的语法是如何工作的。

I did a lot of googling and couldn't seem to come up with much of an answer, how does the syntax of calling Cordova plugins in Ionic 2 work.

例如,在Ionic 1:
我使用的是facebook插件,我会称之为:$ cordovaFacebook.login([public_profile ,email,name,last_name,first_name,birthday,age_range,link])。then(function(success){

Like for example, in Ionic 1: I was using a facebook plugin, and I would call it like: $cordovaFacebook.login(["public_profile", "email","name","last_name","first_name","birthday","age_range","link"]).then(function (success) {

我也会注入它并将其作为依赖项添加。这两件事我不知道如何处理Ionic 2。

I would also 'inject' it and add it as a dependency. Both things I am not sure how to do with Ionic 2.

我在某处阅读了离子2不是必须的,但我仍然不确定

I read somewhere that with Ionic 2 that isn't as nesscary, but I am still unsure

推荐答案

使用cordova插件的步骤:

Steps to use cordova plugin:


  1. 添加插件

  1. Add plugin

cordova插件添加[插件名称]

cordova plugin add [name of plugin]

实际上这是使用cordova插件的唯一步骤。但是当你使用Typescript时可能会出现错误信息。例如:

Actually this is the only step to use cordova plugin. But there could be an error message when you're using Typescript. For example:


[默认] /Users/myname/Projects/ionic2/demo/app/pages/home/home.ts:21中的错误: 12
物业'设备'不存在o n键入'Navigator'。

ERROR in [default] /Users/myname/Projects/ionic2/demo/app/pages/home/home.ts:21:12 Property 'device' does not exist on type 'Navigator'.




  1. 修复错误消息打字稿。您可以简单地将此行添加到.ts文件中,例如:

  1. To fix the error message for Typescript. You can simple add this line to your .ts file, for example:

声明var navigator:any;

declare var navigator : any;

这篇关于Ionic 2:使用Cordova插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆