Search code examples
cordovaionic-frameworkcordova-plugins

Difference between $cordovaCamera and navigator.camera


While working on an Ionic app , i came across many usages of cordova plugins. like how to take picture from camera or how to pick contacts from phonebook , but i found several examples using two different ways to do it .

For example :

1: using $cordovaCamera (example)

2: navigator.camera (example)

My Question is what exactly is the difference between the two , is it because of the Cordova versions ?

I also see the using navigator.camera does not require ngCordova to be injected in the module whereas using $cordovaCamera requires .

Thansks!!


Solution

  • You are asking about two common usages of Cordova plugins as follows:

    Cordova Only:

    This is where you only make use of Cordova plugins without additional libraries and plugins are basically available under navigator object, like (navigator.camera).

    Cordova Docs: https://cordova.apache.org/

    Cordova + AngularJS = ngCordova

    If you use AngularJS, ngCordova will provide you with simple AngularJS wrappers (i.e $cordovaCamera) for the most popular Cordova and PhoneGap plugins available, and you'll still be able to access plugins using navigator object.

    ngCordova Docs: http://ngcordova.com/docs/

    Since Ionic Framework makes use of ngCordova, plugins are accessible using either ngCordova wrappers like $cordovaCamera or navigator object navigator.camera.