Ionic 2:使用 Cordova 插件 [英] Ionic 2: Using Cordova Plugins
问题描述
我做了很多谷歌搜索,似乎无法找到太多答案,在 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.
我在某处读到 Ionic 2 不是那么必要,但我仍然不确定
I read somewhere that with Ionic 2 that isn't as nesscary, but I am still unsure
推荐答案
cordova 插件使用步骤:
Steps to use cordova plugin:
添加插件
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导航器"类型不存在设备"属性.
ERROR in [default] /Users/myname/Projects/ionic2/demo/app/pages/home/home.ts:21:12 Property 'device' does not exist on type 'Navigator'.
修复 Typescript 的错误消息.您可以简单地将此行添加到 .ts 文件中,例如:
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屋!