ngCordova Released

This post is more than 2 years old.

So I know (think?) there is a significant portion of my audience who do not use Twitter, and for those of you who have avoided that trap (don't let anyone fool you, it is a trap), you may have missed me recently raving about the Ionic Framework. Briefly, Ionic is a way to work with Cordova/PhoneGap apps using Angular directives. It has an incredible collection of UI and UX controls that can be helpful to you. I'm still new to Angular and I've found their controls easy to use. I plan on blogging about this a bit more later, but I wanted to tell you about something else these folks created - ngCordova.

ngCordova is a set of Angular directives focused on Cordova APIs. For folks who already use Angular, this provides an easier and more "Angular-ish" way to work with Cordova. As an example (and yes, I stole this right from the docs), here is how you would make use of the Camera API:



module.controller('PictureCtrl', function($scope, $cordovaCamera) {

  $scope.takePicture = function() {
    $cordovaCamera.getPicture({

      // See all the possible Camera options from the Camera docs [1]:
      /// https://github.com/apache/cordova-plugin-camera/blob/master/doc/index.md#cameraoptions

    }).then(function(imageData) {

      // Success! Image data is here

    }, function(err) {

      // An error occured. Show a message to the user

    });
  }

});

And here is a bar code example:


module.controller('MyCtrl', function($scope, $cordovaBarcodeScanner) {
  $cordovaBarcodeScanner.scan().then(function(result) {
    // Scanner result
  }, function(err) {
  });

As you can see, it is all promisy (yes, that is a new word) and a bit simpler to work with in my opinion. I'd like to see more of course (the File API really needs to be implemented as well - it needs promises bad) but it is off to a great start.

Check it out. And - oh yes - it is 100% free and open source!

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Martin Cisneros posted on 6/4/2014 at 10:34 PM

Wow! i just started learning Angular just because of Ionic and this is so good :) BTW im learning at codeschool.com the course is free and very well explained

Comment 2 by Raymond Camden posted on 6/4/2014 at 10:40 PM

I just tweeted that - hope you don't mind. :)

Comment 3 by Martin Cisneros posted on 6/4/2014 at 11:13 PM

No problem :) BTW i'm a part of your audience who do not use Twitter, i avoided the trap hehe, i have an account but i dont use it. Regards.

Comment 4 by Tyler Clendenin posted on 6/5/2014 at 1:42 AM

RSS4Lyfe

Comment 5 by GFoley83 posted on 6/5/2014 at 2:39 AM

Can it be used without Ionic? Can't seem to get it working.

Comment 6 by Raymond Camden posted on 6/5/2014 at 3:44 AM

According to the docs, you don't need it. But maybe I'm reading it wrong. I'd file a bug report on the Git repo (it is either a bug that the dependency isn't documented or a bug in - well whatever you did) and let us know back here please.

Comment 7 by GFoley83 posted on 6/9/2014 at 12:16 AM

Looks like you don't need Ionic but I haven't been able to stand up a there demo app (from the ngCordova repo) on PhoneGap yet. Geolocation works but not the camera or device or accelerometer, though I may just be missing something.

Comment 8 by Raymond Camden posted on 6/9/2014 at 12:37 AM

Did you file an issue on the GH repo?

Comment 9 by Carlos posted on 6/13/2014 at 12:32 PM

I've used this one recently in an ionic project and it's very confortable. good job

Comment 10 by FileAPI with promises posted on 8/7/2014 at 6:24 AM

"the File API really needs to be implemented as well - it needs promises bad"
Have a look at https://gist.github.com/ker... . It's FileAPI with q.js and it works great!

Comment 11 by Raymond Camden posted on 8/7/2014 at 6:27 AM

Slick, is that you Kerri? You didn't use a real name.

Comment 12 by Putra posted on 8/22/2014 at 10:03 AM

do you have a ebook for ngcordova? very hard to learn this. documentation wasnt good.

Comment 13 by Raymond Camden posted on 8/22/2014 at 3:53 PM

Nope - best I can suggest is to report bugs on their project for when things aren't documented clearly.

Comment 14 by innotall posted on 10/2/2014 at 2:43 PM

Hi,
I am using ng-cordova.js and cordova-1.7.0.js in android application
I tried to get my device uuid but it returns "ReferebceError: device is not defined"

var indexApp = angular.module('indexApp', ['ui.router', 'ui.bootstrap' , 'ngCordova']);
indexApp.controller('indexCtrl', function($scope, $state, principal,$http,$cordovaDevice) {
try{
alert($cordovaDevice.getUUID());
}catch(Exception)
{
alert(Exception);
}
});

Can anyone help, please.
Thank you in advance

Comment 15 by Raymond Camden posted on 10/2/2014 at 3:01 PM

Did you install the Device plugin?

Comment 16 by innotall posted on 10/9/2014 at 2:46 PM

Thank you, you were right i didn't install device plugin,
It works now