Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 2: Using Cordova Plugins

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.

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) {

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

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

like image 302
Joe Caraccio Avatar asked Feb 12 '16 21:02

Joe Caraccio


1 Answers

Steps to use cordova plugin:

  1. Add plugin

    cordova plugin add [name of plugin]

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

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

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

    declare var navigator : any;

like image 75
Bagusflyer Avatar answered Nov 19 '22 11:11

Bagusflyer