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!
Archived Comments
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
I just tweeted that - hope you don't mind. :)
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.
RSS4Lyfe
Can it be used without Ionic? Can't seem to get it working.
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.
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.
Did you file an issue on the GH repo?
I've used this one recently in an ionic project and it's very confortable. good job
"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!
Slick, is that you Kerri? You didn't use a real name.
do you have a ebook for ngcordova? very hard to learn this. documentation wasnt good.
Nope - best I can suggest is to report bugs on their project for when things aren't documented clearly.
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
Did you install the Device plugin?
Thank you, you were right i didn't install device plugin,
It works now